【问题标题】:Access style of a control a modify控件的访问样式 a 修改
【发布时间】:2014-01-23 14:29:18
【问题描述】:
<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 变得可见

【问题讨论】:

  • 您应该将属性绑定到文本框的文本和可见性。所以你可以在代码隐藏中访问。

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


【解决方案1】:

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"/>

【讨论】:

    猜你喜欢
    • 2010-11-13
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 2020-07-31
    • 2011-04-26
    相关资源
    最近更新 更多