Skip to content

Commit 7ddc81b

Browse files
authored
#3853: RelativeSource FindAncestor binding errors (#3862)
1 parent c2c8793 commit 7ddc81b

24 files changed

+134
-162
lines changed

src/MaterialDesignThemes.Wpf/Themes/MaterialDesign3.NavigationDrawer.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Setter Property="FontWeight" Value="Medium" />
1010
<Setter Property="Foreground" Value="{DynamicResource MaterialDesign.Brush.Foreground}" />
1111
<Setter Property="Height" Value="56" />
12-
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
12+
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, FallbackValue=Left}" />
1313
<Setter Property="Margin" Value="0" />
1414
<Setter Property="Padding" Value="8" />
1515
<Setter Property="SnapsToDevicePixels" Value="True" />
@@ -130,7 +130,7 @@
130130
</ControlTemplate>
131131
</Setter.Value>
132132
</Setter>
133-
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
133+
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, FallbackValue=Center}" />
134134
<Setter Property="Width" Value="360" />
135135
<Setter Property="wpf:NavigationDrawerAssist.CornerRadius" Value="26" />
136136
<Setter Property="wpf:NavigationDrawerAssist.IconSize" Value="24" />
@@ -145,5 +145,4 @@
145145
<Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.Primary.Light}" />
146146
<Setter Property="wpf:ThemeAssist.TriggerBrush" Value="{DynamicResource MaterialDesign.Brush.Background}" />
147147
</Style>
148-
149148
</ResourceDictionary>

src/MaterialDesignThemes.Wpf/Themes/MaterialDesign3.ToggleButton.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
</Trigger>
332332
<!-- TODO
333333
<Trigger Property="IsFocused" Value="True">
334-
<Setter Property="BorderBrush" TargetName="normal" Value="{Binding (Custom:ControlsHelper.FocusBorderBrush), RelativeSource={RelativeSource TemplatedParent}}"/>
334+
<Setter Property="BorderBrush" TargetName="normal" Value="{Binding (Custom:ControlsHelper.FocusBorderBrush), RelativeSource={RelativeSource TemplatedParent}}" />
335335
</Trigger>
336336
-->
337337
</ControlTemplate.Triggers>
@@ -653,7 +653,7 @@
653653
<Setter Property="Background" Value="Transparent" />
654654
<Setter Property="BorderThickness" Value="1" />
655655
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
656-
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
656+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground), FallbackValue=Black}" />
657657
<Setter Property="Height" Value="37" />
658658
<Setter Property="HorizontalContentAlignment" Value="Center" />
659659
<Setter Property="Padding" Value="1" />

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
CornerRadius="{Binding Path=(wpf:ButtonAssist.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
5353
Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ElevationAssist.Elevation), Converter={x:Static converters:ShadowConverter.Instance}}" />
5454
<ProgressBar x:Name="ProgressBar"
55-
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}, Path=ActualWidth}"
55+
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}, Path=ActualWidth, FallbackValue={x:Static system:Double.NaN}}"
5656
Height="{TemplateBinding Height}"
5757
HorizontalAlignment="Left"
5858
VerticalAlignment="Center"
@@ -183,7 +183,7 @@
183183
BorderThickness="{TemplateBinding BorderThickness}"
184184
CornerRadius="{Binding Path=(wpf:ButtonAssist.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}" />
185185
<ProgressBar x:Name="ProgressBar"
186-
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}, Path=ActualWidth}"
186+
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}, Path=ActualWidth, FallbackValue={x:Static system:Double.NaN}}"
187187
Height="{TemplateBinding Height}"
188188
HorizontalAlignment="Left"
189189
VerticalAlignment="Center"
@@ -341,7 +341,7 @@
341341
BorderThickness="{TemplateBinding BorderThickness}"
342342
CornerRadius="{Binding Path=(wpf:ButtonAssist.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}" />
343343
<ProgressBar x:Name="ProgressBar"
344-
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}, Path=ActualWidth}"
344+
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}, Path=ActualWidth, FallbackValue={x:Static system:Double.NaN}}"
345345
Height="{TemplateBinding Height}"
346346
HorizontalAlignment="Left"
347347
VerticalAlignment="Center"
@@ -386,7 +386,6 @@
386386
<ControlTemplate.Triggers>
387387
<Trigger Property="IsMouseOver" Value="true">
388388
<Setter TargetName="border" Property="Background" Value="{Binding Foreground, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={x:Static converters:BrushOpacityConverter.Instance}, ConverterParameter=0.16}" />
389-
390389
</Trigger>
391390
<Trigger Property="IsEnabled" Value="false">
392391
<Setter Property="Opacity" Value="0.38" />
@@ -474,8 +473,8 @@
474473
<Style x:Key="MaterialDesignToolForegroundButton"
475474
TargetType="{x:Type ButtonBase}"
476475
BasedOn="{StaticResource MaterialDesignToolButton}">
477-
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
478-
<Setter Property="wpf:RippleAssist.Feedback" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
476+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground), FallbackValue=Black}" />
477+
<Setter Property="wpf:RippleAssist.Feedback" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground), FallbackValue=Black}" />
479478
</Style>
480479

481480
<!--#endregion-->
@@ -760,8 +759,8 @@
760759
<Style x:Key="MaterialDesignIconForegroundButton"
761760
TargetType="{x:Type ButtonBase}"
762761
BasedOn="{StaticResource MaterialDesignIconButton}">
763-
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
764-
<Setter Property="wpf:RippleAssist.Feedback" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
762+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground), FallbackValue=Black}" />
763+
<Setter Property="wpf:RippleAssist.Feedback" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground), FallbackValue=Black}" />
765764
</Style>
766765

767766
<!--#endregion-->
@@ -864,5 +863,4 @@
864863
</Style>
865864

866865
<!--#endregion-->
867-
868866
</ResourceDictionary>

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Calendar.xaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
44
xmlns:globalization="clr-namespace:System.Globalization;assembly=mscorlib"
5+
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
6+
xmlns:system="clr-namespace:System;assembly=mscorlib"
57
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf">
68

79
<Style x:Key="MaterialDesignCalendarButton" TargetType="{x:Type CalendarButton}">
@@ -142,7 +144,7 @@
142144
</Grid>
143145
<ControlTemplate.Triggers>
144146
<Trigger Property="HasSelectedDays" Value="False">
145-
<Setter TargetName="NormalText" Property="TextElement.Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" />
147+
<Setter TargetName="NormalText" Property="TextElement.Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}, FallbackValue=Black}" />
146148
</Trigger>
147149
<Trigger Property="IsInactive" Value="True">
148150
<Setter TargetName="NormalText" Property="Opacity" Value="0.56" />
@@ -301,7 +303,7 @@
301303
</Grid>
302304
<ControlTemplate.Triggers>
303305
<Trigger Property="IsSelected" Value="False">
304-
<Setter TargetName="NormalText" Property="TextElement.Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" />
306+
<Setter TargetName="NormalText" Property="TextElement.Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}, FallbackValue=Black}" />
305307
</Trigger>
306308
<Trigger Property="IsInactive" Value="True">
307309
<Setter TargetName="NormalText" Property="Opacity" Value="0.56" />
@@ -315,7 +317,7 @@
315317
</Setter>
316318
<Setter Property="VerticalContentAlignment" Value="Center" />
317319
<Setter Property="MinWidth" Value="28" />
318-
<Setter Property="MinHeight" Value="{Binding ActualWidth, RelativeSource={RelativeSource Self}}"/>
320+
<Setter Property="MinHeight" Value="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" />
319321
<Setter Property="wpf:CalendarAssist.SelectionColor" Value="{DynamicResource MaterialDesign.Brush.Primary}" />
320322
<Setter Property="wpf:CalendarAssist.SelectionForegroundColor" Value="{DynamicResource MaterialDesign.Brush.Primary.Foreground}" />
321323
<Style.Triggers>
@@ -439,8 +441,8 @@
439441
IsEnabled="{TemplateBinding IsEnabled}">
440442
<wpf:MaterialDateDisplay.DisplayDate>
441443
<MultiBinding Mode="OneWay" Converter="{x:Static converters:CalendarDateCoalesceConverter.Instance}">
442-
<Binding Path="DisplayDate" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Calendar}}" />
443-
<Binding Path="SelectedDate" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Calendar}}" />
444+
<Binding Path="DisplayDate" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Calendar}}" FallbackValue="{x:Static system:DateTime.Today}" />
445+
<Binding Path="SelectedDate" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Calendar}}" FallbackValue="{x:Null}" />
444446
</MultiBinding>
445447
</wpf:MaterialDateDisplay.DisplayDate>
446448
</wpf:MaterialDateDisplay>
@@ -492,8 +494,8 @@
492494
RenderTransformOrigin="0, 0.5">
493495
<TextBlock.Text>
494496
<MultiBinding Converter="{x:Static converters:CalendarYearMonthConverter.Instance}">
495-
<Binding Path="DisplayDate" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Calendar}}" />
496-
<Binding Path="Language" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Calendar}}" />
497+
<Binding Path="DisplayDate" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Calendar}}" FallbackValue="{x:Static system:DateTime.Today}" />
498+
<Binding Path="Language" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Calendar}}" FallbackValue="{x:Static x:XmlLanguage.Empty}" />
497499
</MultiBinding>
498500
</TextBlock.Text>
499501
<TextBlock.RenderTransform>
@@ -617,11 +619,11 @@
617619
<Trigger Property="IsEnabled" Value="False">
618620
<Setter TargetName="PART_DisabledVisual" Property="Visibility" Value="Visible" />
619621
</Trigger>
620-
<DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Year">
622+
<DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}, FallbackValue={x:Static controls:CalendarMode.Month}}" Value="Year">
621623
<Setter TargetName="MonthViewWrapperGrid" Property="Visibility" Value="Hidden" />
622624
<Setter TargetName="YearViewWrapperGrid" Property="Visibility" Value="Visible" />
623625
</DataTrigger>
624-
<DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Decade">
626+
<DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}, FallbackValue={x:Static controls:CalendarMode.Month}}" Value="Decade">
625627
<Setter TargetName="MonthViewWrapperGrid" Property="Visibility" Value="Hidden" />
626628
<Setter TargetName="YearViewWrapperGrid" Property="Visibility" Value="Visible" />
627629
</DataTrigger>

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.CheckBox.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@
6363
<Setter Property="Foreground" Value="{DynamicResource MaterialDesign.Brush.Secondary.Foreground}" />
6464
</Style>
6565

66-
6766
<Style x:Key="MaterialDesignCheckBox" TargetType="{x:Type CheckBox}">
6867
<Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.Primary}" />
6968
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.Primary}" />
7069
<Setter Property="BorderThickness" Value="1" />
7170
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
72-
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
71+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground), FallbackValue=Black}" />
7372
<Setter Property="Template">
7473
<Setter.Value>
7574
<ControlTemplate TargetType="{x:Type CheckBox}">
@@ -204,7 +203,7 @@
204203
<Style x:Key="MaterialDesignUserForegroundCheckBox" TargetType="{x:Type CheckBox}">
205204
<Setter Property="BorderThickness" Value="1" />
206205
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
207-
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
206+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground), FallbackValue=Black}" />
208207
<Setter Property="Template">
209208
<Setter.Value>
210209
<ControlTemplate TargetType="{x:Type CheckBox}">

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ColorPicker.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
4-
xmlns:sys="clr-namespace:System;assembly=mscorlib"
4+
xmlns:system="clr-namespace:System;assembly=mscorlib"
55
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf">
66
<ResourceDictionary.MergedDictionaries>
77
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Slider.xaml" />
@@ -177,12 +177,12 @@
177177
<Binding Path="Value" RelativeSource="{RelativeSource TemplatedParent}" />
178178
<Binding>
179179
<Binding.Source>
180-
<sys:Double>1</sys:Double>
180+
<system:Double>1</system:Double>
181181
</Binding.Source>
182182
</Binding>
183183
<Binding>
184184
<Binding.Source>
185-
<sys:Double>1</sys:Double>
185+
<system:Double>1</system:Double>
186186
</Binding.Source>
187187
</Binding>
188188
</MultiBinding>
@@ -241,12 +241,12 @@
241241
<Binding Path="Value" RelativeSource="{RelativeSource TemplatedParent}" />
242242
<Binding>
243243
<Binding.Source>
244-
<sys:Double>1</sys:Double>
244+
<system:Double>1</system:Double>
245245
</Binding.Source>
246246
</Binding>
247247
<Binding>
248248
<Binding.Source>
249-
<sys:Double>1</sys:Double>
249+
<system:Double>1</system:Double>
250250
</Binding.Source>
251251
</Binding>
252252
</MultiBinding>

0 commit comments

Comments
 (0)