简体   繁体   中英

Storyboard accessing property in controltemplate

I have the following problem of accessing a property inside a controltemplate. I have the following controltemplate:

<Button BorderBrush="Transparent" BorderThickness="0" Command="{Binding PopUpOpenCommand}" CommandParameter="{Binding}" Name="OpenPopUp">
            <Button.Template>
                <ControlTemplate>
                    <Path x:Name="CountryUser" Stretch="Fill" StrokeThickness="{StaticResource StrokeUserControl}"  StrokeLineJoin="Round" Stroke="{Binding CountryView.CountryColor}" Data="{Binding CountryView.MapData}" Fill="{StaticResource CountryBackground}"/>
                </ControlTemplate>
            </Button.Template>
        </Button>

I want to have the following storyboard change an element inside the controltemplate.

<Storyboard x:Name="storyboard1">
     <ColorAnimation Storyboard.TargetName="CountryUser" Storyboard.TargetProperty="Stroke" To="Blue"/>
</Storyboard>

How do I do this in XAML ?

From code behind I found Storyboards cant find ControlTemplate elments . I can with no problem find the element in my MVVM structure. but seems like the answer does not work for Windows Phone? As I cannot begin a storyboard with two inputs?

Another Idea

I set the storyboard inside the template. But I then have the problem I cannot access the resource through my MVVM structure. Here is the code:

    <Button BorderBrush="Transparent" BorderThickness="0" Command="{Binding PopUpOpenCommand}" CommandParameter="{Binding}" Name="OpenPopUp">
        <Button.Template>
            <ControlTemplate>
                <Path x:Name="CountryUser" Stretch="Fill" StrokeThickness="{StaticResource StrokeUserControl}"  StrokeLineJoin="Round" Stroke="{Binding CountryView.CountryColor}" Data="{Binding CountryView.MapData}" Fill="{StaticResource CountryBackground}">
                      <Storyboard x:Name="storyboard1">
                           <ColorAnimation Storyboard.TargetName="CountryUser" Storyboard.TargetProperty="Stroke" To="Blue"/>
                      </Storyboard> 
                </Path>
            </ControlTemplate>
        </Button.Template>
    </Button>

But how do I get access to the storyboard. I cannot use Template.Find, as this does not exist on windows phone?

<Button x:Name="Button1" BorderThickness="0" BorderBrush="Transparent">
<Button.Template>
    <ControlTemplate x:Name="Control">
        <Path x:Name="CountryUser" Style="{StaticResource style_ColorButton}" Data="{Binding UserView.buttonData}" Fill="{StaticResource ButtonBackground}">
            <Path.Resources>
                <Storyboard x:Name="StoryBoard1">
                    <ColorAnimation Storyboard.TargetName="User" Storyboard.TargetProperty="(Stroke).(SolidColorBrush.Color)" To="Blue" Duration="0"/>
                </Storyboard>
            </Path.Resources>
        </Path>
    </ControlTemplate> 
</Button.Template>

and activation

foreach (UIElement x in ElementsAtPoint)
{
    f = x as FrameworkElement;
    if (f is Path)
    {
        try { 
        h = f as Path;
        Storyboard sb = h.Resources["StoryBoard1"] as Storyboard;
        sb.Begin();
            }
        catch
        {

        }
        break;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM