当前位置: 代码迷 >> .NET Framework >> 急WPF,该如何处理
  详细解决方案

急WPF,该如何处理

热度:108   发布时间:2016-05-02 00:44:44.0
急急急急!!--WPF
我刚接触WPF,想做一个多选功能,复选框在ListView控件中

如果可以的话,可以给个简单的Demo嘛??

谢谢!

------解决方案--------------------
界面上的代码
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="那种语言你感兴趣!"/>
<ListView Grid.Row="1" Name="interestLanguge">
<CheckBox Name="csharp" Content="C#"/>
<CheckBox Name="java" Content="Java"/>
<CheckBox Name="php" Content="PHP"/>
<CheckBox Name="cplusplus" Content="C++"/>
<CheckBox Name="c" Content="C"/>
</ListView>
<Button Grid.Row="2" Content="提交" Click="Button_Click"></Button>
<TextBlock Grid.Row="3" Name="yourinterestLanguage" Visibility="Collapsed"/>
</Grid>
简单的后台代码
 public Window1()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
yourinterestLanguage.Text = "你对:";

bool cIsCheck=(bool)c.IsChecked;
bool cSharpIsCheck = (bool)csharp.IsChecked;
bool javaIsCheck = (bool)java.IsChecked;
bool cPlusPlusIsCheck = (bool)cplusplus.IsChecked;
bool phpIsCheck = (bool)php.IsChecked;

if (cIsCheck)
{
yourinterestLanguage.Text += " C";
}

if (cSharpIsCheck)
{
yourinterestLanguage.Text += " C#";
}

if (javaIsCheck)
{
yourinterestLanguage.Text += " JAVA";
}

if (phpIsCheck)
{
yourinterestLanguage.Text += " PHP";
}

if (cPlusPlusIsCheck)
{
yourinterestLanguage.Text += " C++";
}

yourinterestLanguage.Text += "感兴趣.";
yourinterestLanguage.Visibility = Visibility.Visible;

}
  相关解决方案