首页新闻找找看学习计划

wpf中ListBox的绑定问题

0
[待解决问题]

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为相应的数据库类型,请问这个绑定怎么实现?

MaxFish的主页 MaxFish | 初学一级 | 园豆:148
提问于:2018-10-11 15:35
< >
分享
所有回答(1)
0

给RadioButton加id,后台获取id进行判断绑定相应的数据库类型

徒然喜欢你 | 园豆:1212 (小虾三级) | 2018-10-11 15:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册