wpf将一些xaml转换为c#

时间:2011-06-04 18:21:05

标签: c# wpf xaml

电子 我在下面的链接中收到了一个很好的答案,我需要对此进行编码,因为我没有设置椭圆数的设置值。我很难将它转换为c#并希望得到一些帮助。答案是Start storyboard on a different control on a trigger in WPF

代码:

<Ellipse Width="25" Height="25" Name="ellipse2">
    <Ellipse.Style>
        <Style TargetType="{x:Type Ellipse}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Opacity, ElementName=ellipse1}" Value="0.5">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <!-- Storyboard for ellipse 2 here -->
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Ellipse.Style>
</Ellipse>

1 个答案:

答案 0 :(得分:3)

这样的事情:

var style = new Style(typeof(Ellipse));
var trigger = new DataTrigger();
trigger.Binding = new Binding("Opacity") { ElementName = "ellipse1" };
trigger.Value = 0.5;
Storyboard sb = new Storyboard();

//Add animation to sb, note the attached storyboard properties which are set with static methods:
//Storyboard.SetTarget(...);
//Storyboard.SetTargetProperty(...);
//Storyboard.SetTargetName(...);

trigger.EnterActions.Add(new BeginStoryboard() { Storyboard = sb });
style.Triggers.Add(trigger);