silverlight 4 知识归类与汇总(二)常用控件篇

ContentPropertyAttribute 类

指定在通过 XAML 处理器分析某个类时,可以将该类的哪个属性解释为内容属性。(XAML子元素隐式添加到的属性)

            <local:User UserCode="aaa">
                A
            </local:User>

(该子元素将添加到其Name属性中)

[System.Windows.Markup.ContentProperty("UserName")]
public class User 
{
    public string UserName { get; set; }
    public string UserCode { get; set; }
    public string Email { get; set; }
}

1 内容控件

只包含单一项的控件,其Content属性的类型为object

如果其内容为UIElement或者模板,则对其进行渲染,否则调用ToString()方法,将返回值放到TextBlock里

 

  • 以编程方式点击一个按钮
void Do()
{
    //模拟按钮点击
   ButtonAutomationPeer bap = new ButtonAutomationPeer(Button1);
    IInvokeProvider iip = bap.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
    iip.Invoke();
}
  • CheckBox与RadioButton都继承自ToggleButton,其IsChecked属性是一个Nullable<Boolean>的值
  • 当RadioButton没有显示设置GroupName时,其互斥性是基于所在的组,下面代码将前4个与后2个RadioButton分为了两组
        <StackPanel Height="80" HorizontalAlignment="Left" Margin="8,109,0,0" VerticalAlignment="Top" Width="200">
            <RadioButton Content="RadioButton" Name="radioButton" GroupName="A"/>
            <RadioButton Content="RadioButton" Height="16" Name="radioButton1" GroupName="A"/>
            <RadioButton Content="RadioButton" Height="16" Name="radioButton2" GroupName="A"/>
        </StackPanel>
        <StackPanel Height="88" HorizontalAlignment="Left" Margin="8,200,0,0" VerticalAlignment="Top" Width="200">
            <RadioButton Content="RadioButton" Height="16" Name="radioButton3" GroupName="A"/>
            <RadioButton Content="RadioButton" Height="16" Name="radioButton4" />
            <RadioButton Content="RadioButton" Height="16" Name="radioButton5" />
        </StackPanel>

2 Item控件

ItemsControl 把它的内容包含在Items属性中

DisplayMemberPath可以指定其每一项的属性的名字

posted on 2010-09-26 10:10  imbob  阅读(440)  评论(0编辑  收藏  举报

导航