【问题标题】:Issue templating RadioButton in Silverlight 5Silverlight 5 中的问题模板 RadioButton
【发布时间】:2013-11-06 10:00:12
【问题描述】:

我尝试将一个非常简单的 ControlTemplate 应用于 RadioButton。但这会导致一种奇怪的行为。 只要我只是单击标签,一切正常,但是当我单击按钮控件本身时,它就再也不会改变了。这里是控件的完整代码:

    <UserControl x:Class="RadioButtonDemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
    <ControlTemplate TargetType="RadioButton" x:Key="RadioButtonTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="2*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="{TemplateBinding Content}"/>
            <RadioButton IsChecked="{TemplateBinding IsChecked}" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center"/>
        </Grid>
    </ControlTemplate>

    <Style TargetType="RadioButton" x:Key="RadioButtonStyle">
        <Setter Property="Template" Value="{StaticResource RadioButtonTemplate}"/>
    </Style>

</UserControl.Resources>
<StackPanel>
    <RadioButton Content="Textbox diabled" GroupName="Group1" Style="{StaticResource RadioButtonStyle}"/>
    <RadioButton x:Name="EnabledButton" Content="Textbox enabled" GroupName="Group1" Style="{StaticResource RadioButtonStyle}"/>
    <TextBox IsEnabled="{Binding IsChecked, ElementName=EnabledButton}"/>
</StackPanel>

有人可以帮忙吗?

【问题讨论】:

    标签: silverlight xaml silverlight-5.0 controltemplate


    【解决方案1】:

    请从以下链接获取默认样式,

    http://msdn.microsoft.com/en-us/library/cc296247(v=vs.95).aspx

    只需交换内容和按钮即可使用模板(:-(代码是大容量的)。

    【讨论】:

    • 嗯,这对我来说太大了,但它确实有效。问题已回答!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多