wpf - x :Reference? 的替代品是什么

标签 wpf xaml

我的 XAML 如下所示:

<DataTemplate x:Key="CdTeThickness">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <StackPanel Grid.Row = "0" Orientation="Horizontal">
                <CheckBox x:Name="DisplayMarkers"   Content="Display Data Points" Margin="8,5,0,5" HorizontalAlignment="Left" IsChecked="False"/>
                <CheckBox x:Name="DisplayIndicator" Content="Display Indicator"   Margin="8,5,0,5" HorizontalAlignment="Left" IsChecked="False"/>
            </StackPanel>

            <vf:Chart Grid.Row = "1" Style="{StaticResource chartStyle}" IndicatorEnabled="{Binding Source={x:Reference DisplayIndicator}, Path=IsChecked}">
                <vf:Chart.Titles>
                    <vf:Title Text="{Binding Chart.ChartTitle}"/>
                </vf:Chart.Titles>

我的理解是 x:Reference 尚未得到广泛支持。但是,这是我能够绑定(bind)到所需属性 (DisplayIndi​​cator) 的唯一方法,如屏幕截图所示。有人可以建议在这种情况下使用 x:Reference 的替代方案吗?

最佳答案

通常您可以使用ElementName然而具有约束力x:Reference 实际上得到了很好的支持。

{Binding IsChecked, ElementName=DisplayIndicator}

关于wpf - x :Reference? 的替代品是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10653585/

相关文章:

WPF ComboBox 清除

WPF数据网格问题

c# - 如果 XAML 中的字符串太长,则自动在标签中下一行

c# - 如何在设置了ItemsSource的ComboBox顶部插入 “Select All”项目?

c# - UserControl 的本地化属性

c# - XAML 命名空间上的 "does not exist in namespace"错误

c# - 使用 Caliburn 的 TextboxHelper.ButtonCommand 绑定(bind)

c# - RibbonControlsLibrary - 如何禁用最小化?

xaml - TitleView 未覆盖整个工具栏

c# - 切换按钮两种方式绑定(bind)不起作用(通用 Windows 平台)