我想将 contrentcontrol 的内容绑定到组合框的 selectedvalue 并根据触发器设置可见性。但这是行不通的。问题是什么 ?
<DockPanel>
<ComboBox x:Name="combobo" Padding="4" Width="120" HorizontalAlignment="Left" Margin="30,10,0,0" VerticalAlignment="Center">
<ComboBoxItem>0</ComboBoxItem>
<ComboBoxItem>1</ComboBoxItem>
</ComboBox>
<ContentControl x:Name="contentcontrol" Grid.Row="0" Grid.Column="2" Content="{Binding ElementName=combobo, Path=SelectedIndex}" Margin="0,10,0,0" VerticalAlignment="Center"
Visibility="Visible">
<ContentControl.ContentTemplate>
<DataTemplate>
<DockPanel x:Name="WarningGrid" VerticalAlignment="Top" Visibility="Collapsed">
<TextBlock Text="Warning" VerticalAlignment="Center"></TextBlock>
</DockPanel>
<DataTemplate.Triggers>
<Trigger Property="ContentControl.Content" Value="0">
<Setter TargetName="WarningGrid" Property="Visibility" Value="Visible" />
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</DockPanel>
我也用 SelectedIndex 尝试过,但触发器也不起作用。
谢谢。