Вопрос

I have 2 questions.

1st. I am using Silverlight for windows embedded compact 7 and i have some problems with bindings.

i have template like this

<Style TargetType="RadioButton" x:Key="VoltageTab">
    <Setter Property="Width" Value="95"/>
    <Setter Property="Height" Value="61"/>
    <Setter Property="Margin" Value="193,0,192,3"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="VerticalAlignment" Value="Bottom"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RadioButton">
                    <Grid Background="#00000000">
                            <Image x:Name="UnCheckedimg" Source="12.png"/>
                            <Image x:Name="Checkedimg" Visibility="Collapsed" Source="11.png"/>
                            <TextBlock x:Name="ModeName" FontSize="20" FontFamily="Alternate_Gothic_No.ttf#Alternate-Gothic-No3" Text="VOLTAGE" Foreground="#D25A32" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,4,0,0" />
                            <TextBlock  x:Name="ModeValue" FontSize="20" FontFamily="Alternate_Gothic_No.ttf#Alternate-Gothic-No3" Text="{TemplateBinding Content}" HorizontalAlignment="Center"  VerticalAlignment="Bottom" Margin="0,0,0,2"/>
                            <TextBlock x:Name="ModeNameChecked" Visibility="Collapsed" FontSize="34" FontFamily="Alternate_Gothic_No.ttf#Alternate-Gothic-No3" Text="VOLTAGE" Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

I use TemplateBinding to bind ModeValue textblock, but i need another binding to bind ModeName. Can somone point me how to do this?

  1. I have another style

EDIT: 2nd style is posted below because editor didnt alowe me to post it here

It works ok if i only put text into content, but i want to you Run objects so i can format text inside buttons.

Is this possible and if not is there some other way to achive this?

Please keep in mind that i use Silverlight For Windows embedded.

Best regards, Luka


 <Style x:Key="FunctionSelectButton" TargetType="RadioButton">
    <Setter Property="Width" Value="154"/>
    <Setter Property="Height" Value="61"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RadioButton">
                    <Grid Background="#00000000">
                        <Image x:Name="NormalImg" Source="mode_unpressed.png" Stretch="None"/>
                        <TextBlock x:Name="NormalText" Foreground="#D25A32" FontSize="26" FontFamily="Alternate_Gothic_No.ttf#Alternate-Gothic-No3" HorizontalAlignment="Center" Text="{TemplateBinding Content}" VerticalAlignment="Center" Margin="0,0,0,0"></TextBlock>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Image for easyer representation -> Image

Это было полезно?

Решение

To answer your first question, look here.

Your 2nd question though, I'm not sure I understand entirely what the question is, but what I think you're looking for would be setting it as a ContentPresenter with contenttemplate instead like;

<Style x:Key="FunctionSelectButton" TargetType="RadioButton">
    <Setter Property="Width" Value="154"/>
    <Setter Property="Height" Value="61"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RadioButton">
                    <Grid>
                        <Image x:Name="NormalImg" Source="mode_unpressed.png" Stretch="None"/>
                        <ContentPresenter x:Name="contentPresenter"
                                          Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          Content="{TemplateBinding Content}"
                                          ContentTemplate="{TemplateBinding ContentTemplate}" />

<!--
<TextBlock x:Name="NormalText" Foreground="#D25A32" FontSize="26" FontFamily="Alternate_Gothic_No.ttf#Alternate-Gothic-No3" HorizontalAlignment="Center" Text="{TemplateBinding Content}" VerticalAlignment="Center" Margin="0,0,0,0"></TextBlock>
-->
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

<Button Content="{Binding RPE-2WIRE}" Style="{StaticResource FunctionSelectButton}" FontFamily="Alternate_Gothic_No.ttf#Alternate-Gothic-No3" Foreground="#D25A32" FontSize="26" />

At least that's what I think you're saying :)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top