WPF绑定RadioButton控件
比如:<RadioButtonGroupName="r"Content="1"/><RadioButtonGroupName="r"Content="2"/><TextB...
比如:
<RadioButton GroupName="r" Content="1" />
<RadioButton GroupName="r" Content="2" />
<TextBlock Text="{Binding Path=Content,Source={上面RadioButton选中的控件}}" 展开
<RadioButton GroupName="r" Content="1" />
<RadioButton GroupName="r" Content="2" />
<TextBlock Text="{Binding Path=Content,Source={上面RadioButton选中的控件}}" 展开
1个回答
展开全部
其实很简单的啦。我给你一个方案:
前台:<Grid x:Name="LayoutRoot" Background="White" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel x:Name="sp" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<RadioButton x:Name="ra" Content="1" Checked="Checked"/>
<RadioButton x:Name="rb" Content="2" Checked="Checked"/>
</StackPanel>
<TextBlock Grid.Row="1" x:Name="tb" Text="{Binding ElementName=sp, Path=Tag}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
后台:
private void Checked(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb == null) return;
if (rb.IsChecked == true)
{
sp.Tag = rb.Content;
}
}
前台:<Grid x:Name="LayoutRoot" Background="White" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel x:Name="sp" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<RadioButton x:Name="ra" Content="1" Checked="Checked"/>
<RadioButton x:Name="rb" Content="2" Checked="Checked"/>
</StackPanel>
<TextBlock Grid.Row="1" x:Name="tb" Text="{Binding ElementName=sp, Path=Tag}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
后台:
private void Checked(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb == null) return;
if (rb.IsChecked == true)
{
sp.Tag = rb.Content;
}
}
更多追问追答
追问
谢谢你的回答,但是如果还是通过后台获取的话就不是我想要的了。。。
追答
那你要看你前台和后台获取的是什么。。。你这个需求完全前台是不可能做到的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询