zoukankan      html  css  js  c++  java
  • WPF 怎样实现单选列表控件?

    WPF没有像ASP.NET提供一个RadioButtonList的控件。幸运的是,我们可以利用WPF样式和模板的强大功能,用纯粹的XAML代码实现这个功能

    <Window x:Class="ControlTest2.ListBoxTest2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:s="clr-namespace:System;assembly=mscorlib">
        <Window.Resources>
            <x:Array Type="{x:Type s:String}" x:Key="data">
                <s:String>Option1</s:String>
                <s:String>Option2</s:String>
                <s:String>Option3</s:String>
            </x:Array>
        </Window.Resources>
        <StackPanel DataContext="{StaticResource data}">
          <TextBlock Margin="5">
           <TextBlock Text="Current Option:"/>
           <TextBlock Text="{Binding /}"/>
        </TextBlock>
          <ListBox
           ItemsSource="{Binding}"
           IsSynchronizedWithCurrentItem="True"
           Width="240"
           Height="60"
           HorizontalAlignment="Left">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <RadioButton
                                        IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}}"
                                        Content="{TemplateBinding Content}"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
            <!--这种方法跟简单-->
             <StackPanel>
                <RadioButton GroupName="x">Radio1</RadioButton>
               <RadioButton GroupName="x">Radio2</RadioButton>
               <RadioButton GroupName="x">Radio3</RadioButton>
            </StackPanel>
        </StackPanel>   
    </Window> 
    

      参考:http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/thread/857fdaa9-5c67-4e0a-a1fd-037f72577c76

  • 相关阅读:
    php-基于面向对象的MySQL类
    php-迭代创建级联目录
    php-删除非空目录
    php-递归创建级联目录
    linux 用户管理
    mysql 语法大全
    dos命令下修改mysql密码的方法
    对 linux init.d的理解
    linux 重启服务器命令
    校验软件包
  • 原文地址:https://www.cnblogs.com/linlf03/p/2248381.html
Copyright © 2011-2022 走看看