访问控件的样式修改

时间:2014-01-23 14:29:19

标签: c# windows-8 bing-maps windows-8.1

<UserControl.Resources>
    <Style x:Key="PushPinStyle" TargetType="Maps:Pushpin">
        <Setter Property="Width" Value="250"/>
        <Setter Property="Height" Value="80"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Foreground="Red" Text="HERE MUST BE TEXT" Grid.Row="0"/>
                        <Image Grid.Row="1" Source="ms-appx:///Images/Icons/Pushpin.png" Stretch="Uniform" HorizontalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

当我创建图钉时:

Pushpin pushpin = new Pushpin();
pushpin.Style = this.Resources["PushPinStyle"] as Style;

我想从C#代码访问文本块的文本和可见性属性。

页面上会出现“转到下一个图钉”按钮,地图以其他图钉为中心,TextBlock变得可见

1 个答案:

答案 0 :(得分:0)

Xyroid的评论帮助了我:

<TextBlock Foreground="Red" HorizontalAlignment="Center" Visibility="{Binding Path=Visibility}" Text="{Binding Path=Label}" Grid.Row="0"/>
<Image Grid.Row="1" Source="ms-appx:///Images/Icons/Pushpin.png" Stretch="Uniform" HorizontalAlignment="Center"/>