I'm trying to bind to the DataContext
of an element from within a Style
, which for some reason is resulting in a 'catastrophic failure' in the XAML parser. Here is the code:
<UserControl
x:Class="Sirloin.AppView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Sirloin"> <!--A few lines omitted for brevity-->
<UserControl.Resources>
<ResourceDictionary>
<Style x:Key="MenuButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<!--This fails-->
<Setter Property="Content" Value="{Binding Symbol}"/>
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"/>
<!--And this too-->
<Setter Property="Width" Value="{Binding CompactPaneLength, ElementName=splitView}"/>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<SplitView x:Name="splitView" DisplayMode="CompactOverlay">
<SplitView.Pane>
<Grid>
<!--The hamburger-->
<Button Grid.Row="0" Style="{StaticResource MenuButtonStyle}">
<Button.DataContext>
<local:MenuItem Symbol=""/>
</Button.DataContext>
</Button>
</Grid>
</SplitView.Pane>
</SplitView>
</UserControl>
When I attempt to compile this in Visual Studio, this is the error message that results:
I've tried mucking around with the Bindings
a bit and changing the RelativeSource
, but to no avail; the same error message pops up each time.
Why does this happen, and what can I do to fix it?