簡體   English   中英

如何在后面的代碼中訪問控件庫?

[英]How to access a control templace in code behind?

我是一名新的Windows Phone開發人員,並且有很多問題。 我目前的問題是這樣的:

我有以下代碼:

<Button x:Name="InfoEllipse" 
                Foreground="White"
                HorizontalAlignment="Right"
                VerticalAlignment="Center"   
                Margin="0,0,25,0" 
                MinWidth="34" MinHeight="31" 
                   Click="InfoEllipse_Click">
            <Button.Template>
                <ControlTemplate x:Name="EllipseControlTemplate">
                    <Border x:Name="EllipseButtonBorder"
                            BorderBrush="#4387C4" 
                        Background="#4387C4" 
                        CornerRadius="20,20,20,20"
                            BorderThickness="2">
                    </Border>
                </ControlTemplate>
            </Button.Template>
        </Button>

所有這些代碼都放在UserControl xaml中。 我的問題是我想在后面的代碼中訪問我的Border->'EllipseButtonBorder',以便當我單擊此按鈕更改此邊框背景時。 問題是我無法在后面的代碼中弄清楚如何訪問此EllipseButtonBorder 請一些幫助。 我正在使用Windows Phone 8。

您應該使用VisualState來管理按鈕的狀態。

<Button x:Name="InfoEllipse" 
    Foreground="White"
    HorizontalAlignment="Right"
    VerticalAlignment="Center"   
    Margin="0,0,25,0" 
    MinWidth="34" MinHeight="31" 
    Click="InfoEllipse_Click">
    <Button.Template>
        <ControlTemplate x:Name="EllipseControlTemplate">
            <Border x:Name="EllipseButtonBorder"
                BorderBrush="#4387C4" 
                Background="#4387C4" 
                CornerRadius="20,20,20,20"
                BorderThickness="2">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="MouseOver"/>
                        <VisualState x:Name="Pressed">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="EllipseButtonBorder">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Green"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Disabled" />
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
            </Border>
        </ControlTemplate>
    </Button.Template>
</Button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM