C#代码如下:
public class DataSourceViewModel : Screen
{
public Guid Id { get; set; }
public string DBType { get; set; } = "Oracle";
public string DBAlias { get; set; } = "test";
public string DBConnUrl { get; set; } = "127.0.0.1";
public bool ConnStatus { get; set; }
}
xaml代码如下:
<ListBox x:Name="ListBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SelectedItem="{Binding Path=DBType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="10 0 10 0">
<ListBox.Template>
<ControlTemplate TargetType="{x:Type ListBox}">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<WrapPanel Orientation="Horizontal" IsItemsHost="True" ScrollViewer.CanContentScroll="True"/>
</ScrollViewer>
</ControlTemplate>
</ListBox.Template>
<ListBox.Items>
<RadioButton Width="155">SQL Server</RadioButton>
<RadioButton Width="155">Oracle</RadioButton>
<RadioButton Width="155">Access</RadioButton>
<RadioButton Width="155">DB2</RadioButton>
<RadioButton Width="155">MySQL</RadioButton>
<RadioButton Width="155">SQLite</RadioButton>
<RadioButton Width="155">PostgreSQL</RadioButton>
</ListBox.Items>
</ListBox>
问题描述:
当我DataSourceViewModel 中的DBType为Oracle时,界面中显示的效果为RadioButton Width="155">Oracle</RadioButton>选中,当选中其他RadioButton时,对应的DataSourceViewModel 中的DBType为相应的数据库类型,请问这个绑定怎么实现?
给RadioButton加id,后台获取id进行判断绑定相应的数据库类型