Why do I need to reimplement a ResourceDictionary to access some of it's properties? #18344
-
I am new to Avalonia UI, so my question might not be asked ideally. I will try to explain it through code and see if I can get my point across that way. We are using the Fluent theme. So, we created a Checkbox UserControl to implement some logic that has to do with validation, among other things: <reactiveUi:ReactiveUserControl x:TypeArguments="configuration:CheckboxConfigEntryViewModel"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveUi="http://reactiveui.net"
xmlns:configuration="clr-namespace:MyApp.ViewModels.Configuration.ConfigEntries"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MyApp.Views.Configuration.ConfigEntries.CheckboxConfigEntryView"
x:DataType="configuration:CheckboxConfigEntryViewModel"
Classes.DisabledConfigEntry="{Binding !IsEnabled}">
<UserControl.Styles>
<StyleInclude Source="/Styles/ConfigExpanderPanelStyles.axaml" />
</UserControl.Styles>
<ToolTip.Tip>
<TextBlock x:Name="LblToolTip" />
</ToolTip.Tip>
<Grid HorizontalAlignment="Stretch"
RowDefinitions="Auto,Auto"
ColumnDefinitions="Auto,Auto,*">
<CheckBox Grid.Row="0" Grid.Column="1"
x:Name="ChkPropertyValue"
IsThreeState="False"
AutomationProperties.Name="{Binding AutomationName}"
AutomationProperties.AutomationId="{Binding AutomationId}" />
<TextBlock Grid.Row="0" Grid.Column="2"
x:Name="LblPropertyName"
Classes="ExpanderLbl" />
<TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
x:Name="LblValidationError"
Classes="ValidationError" />
</Grid>
</reactiveUi:ReactiveUserControl> I changed the height and width of the checkbox per a specification I was given by our design team, but then the checkbox was clipped on the right side. Using the devtools I can see where the issue comes from <CheckBox Grid.Row="0" Grid.Column="1" Height="16" Width="16"
x:Name="ChkPropertyValue"
IsThreeState="False"
AutomationProperties.Name="{Binding AutomationName}"
AutomationProperties.AutomationId="{Binding AutomationId}">
<CheckBox.Styles>
<Style Selector="CheckBox /template/ Grid#RootGrid Grid">
<Setter Property="Background" Value="Lime" />
</Style>
</CheckBox.Styles>
</CheckBox> It did not find it. I tried all sorts of things to find that control and couldn't find any luck. I did get it to work eventually by making a new ResourceDictionary, copying the contents from the Fluent theme repo and implementing that instead like the following: <UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="/Controls/Checkbox.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources> Then I can just edit the control directly. However, this brings with it two problems. It adds a whole new file with many more lines of code than I actually needed to change. Secondly, if the repo gets updated for the Fluent theme, we will not get that update because we are overwriting the entire thing. So, my question is this, was there a selector that I am missing that would have let me select that grid or did I just fundamentally misunderstand something about Avalonia UI? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Can you clarify your post? First you say:
Then show an example of a selector that does as such. Which works in my testing. Then you say:
??? For some general insight, selectors can fail to work as expected for a number of reasons. The biggest reasons are that devs don't read the underlying For your issue, |
Beta Was this translation helpful? Give feedback.
Can you clarify your post?
First you say:
Then show an example of a selector that does as such. Which works in my testing. Then you say:
???
For some general insight, selectors can fail to work as expected for a number of reasons. The biggest reasons are that devs don't read the underlying
ControlTheme
for the theme they're using nor do they understand setter precedence. It's similar to using an API that you haven't read the docs for. Themes are opin…