gpt4 book ai didi

c# - WPF 绑定(bind)到选定的单选按钮

转载 作者:行者123 更新时间:2023-11-30 20:50:10 25 4
gpt4 key购买 nike

我有一个 Radiobutton 组:

 <RadioButton Name="_CreateGraph" GroupName="MapOrGraph" Content="Create Graph" />
<RadioButton Name="_CreateMap" GroupName="MapOrGraph" Content="Create Map" />

如何将标签的内容绑定(bind)到所选单选按钮的内容?

例如标签应该根据创建的单选框显示 Create Graph 或 Create Map?

最佳答案

<Label Content="{Binding SelectedValue.Content, ElementName=list}"  />

<ListBox x:Name="list" SelectedIndex="1" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem" >
<RadioButton GroupName="a" Content="{TemplateBinding Content}" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent} }" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBoxItem>Create Graph</ListBoxItem>
<ListBoxItem>Create Map</ListBoxItem>
</ListBox>

我认为你可以让它比我做的更短。

关于c# - WPF 绑定(bind)到选定的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22762693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com