标签: visualstatemanager

在VisualState Storyboard中使用绑定

我正在为WPF应用程序编写自定义控件.我想StoryboardVisualState定义中使用颜色动画.该To动画的属性应绑定到我的控件对象的依赖项属性.这似乎不起作用.

我在Silverlight论坛中找到了一个线程,描述了完全相同的问题,声称这可以在SL4 RTM中运行:http://forums.silverlight.net/forums/p/174655/423324.aspx.但是,当我尝试使用我的VS2010 WPF应用程序中发布的代码时,它不起作用,这意味着颜色不会改变.我能在a内完成的唯一约束VisualState StoryboardStaticResource.

有任何想法吗?

编辑:

添加了代码段:

来自Generic.xaml:

<Style TargetType="{x:Type local:TestCustomControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:TestCustomControl}">
                <Border BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Name="MyBorder">
                    <Border.Background>
                        <SolidColorBrush Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ColdColor}" />
                    </Border.Background>

                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <!-- This works: -->
                                    <!--<ColorAnimation Storyboard.TargetProperty="Background.Color" Storyboard.TargetName="MyBorder" To="Red"  Duration="0:0:0.2"/>-->

                                    <!-- This also works: --> 
                                    <!--<ColorAnimation Storyboard.TargetProperty="Background.Color" Storyboard.TargetName="MyBorder" To="{StaticResource HotColorRes}"  Duration="0:0:0.2"/>-->

                                    <!-- This doesn't work: -->
                                    <ColorAnimation …
Run Code Online (Sandbox Code Playgroud)

wpf binding visualstatemanager storyboard

5
推荐指数
1
解决办法
2062
查看次数

在列表框中选择时,WPF会更改datatemplate的可视状态

如果我有一个包含自定义用户控件ListBox的基本WPF ,ItemTemplate我如何告诉用户控件在DataTemplate更改其视觉状态时选择ListBox

非常感谢您提供的任何帮助

c# wpf listbox visualstatemanager

4
推荐指数
1
解决办法
3866
查看次数

根据属性值更改VisualState

如何根据WP7上的属性值更改VisualState?

我试图使用MVVM模式,当我的模型加载时,我希望我的视图去特定的VisualState.

在Silverlight中,我们有属性更改的触发器,但在WP7中没有!

PS:我不想使用框架,我想了解它是如何在WP7中完成的.

silverlight mvvm visualstatemanager windows-phone-7

4
推荐指数
1
解决办法
2323
查看次数

程序状态更改在Silverlight中不起作用

我试图通过代码让视觉状态管理器改变状态.

我在用:

Microsoft.Expression.Interactivity.Core.ExtendedVisualStateManager.GoToElementState(this.LayoutRoot, "stateRegistration", true);
Run Code Online (Sandbox Code Playgroud)

但它似乎不想工作,我已经创建了一个事件处理程序和一个监听器,但是在使用该代码时没有状态改变.

谁能帮我吗.

XAML CODE(代码片段):

<Grid x:Name="LayoutRoot" Width="897" Height="699">
<VisualStateManager.VisualStateGroups>
<VisualState x:Name="stateRegistration">
                    <Storyboard>
                        <DoubleAnimation Duration="0" To="870" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="RegisterContent" d:IsOptimized="True"/>
                        <DoubleAnimation Duration="0" To="880" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="HomeContent" d:IsOptimized="True"/>
                        <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="btnRegRegister" d:IsOptimized="True"/>
                        <DoubleAnimation Duration="0" To="-10" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="btnRegRegister" d:IsOptimized="True"/>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
</Grid>
Run Code Online (Sandbox Code Playgroud)

谢谢.

c# silverlight visualstatemanager expression-blend

4
推荐指数
1
解决办法
1581
查看次数

在VisualStateManager(WinRT XAML)中更改ItemTemplate中控件的属性

我有我用于SnapView和Portrait视图的ListView.但是,我想在这两个视图中更改项目模板的某些项目.VisualStateManager似乎是理想的做法,但我无法弄清楚.

这是我的ListView XAML:

<ListView x:Name="SampleListView" ItemsSource="{Binding Samples}" Visibility="Collapsed">
    <ListView.ItemTemplate>
        <DataTemplate>
            <local:SampleBlock SampleText="{Binding ElementName=pageRoot, Path=DataContext.SampleText, Mode=TwoWay}"
                Height="70" Width="Auto" Margin="5" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)

我想使用页面的VisualStateManager 更改我的SampleBlock控件的高度边距.这是我的可视状态管理器,它显示和隐藏我的ListView:

<VisualState x:Name="FullScreenPortrait">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SampleListView" Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SampleGridView" Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

<VisualState x:Name="Snapped">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SampleListView" Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SampleGridView" Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>
Run Code Online (Sandbox Code Playgroud)

有没有办法从页面的VisualStateManager访问项目模板,或者我应该从不同的角度攻击这个?

xaml visualstatemanager windows-runtime winrt-xaml

4
推荐指数
1
解决办法
2769
查看次数

如何正确使用VisualStateManager?

我的代码更改属性不起作用,我完全不知道什么是错的,但也许你这样做.

这是我的代码的简化示例,它重现了错误.这是我的Xaml代码:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Button x:Name="MyButton"
            Height="100" 
            Width="300" 
            Content="Click" 
            FontSize="40" 
            FontWeight="Bold" 
            VerticalAlignment="Center" 
            HorizontalAlignment="Center" 
            Background="Red" Click="MyButton_Click"/>
</Grid>
<VisualStateManager.VisualStateGroups>
    <VisualStateGroup>
        <VisualState x:Name="Blue">
            <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyButton"
                                               Storyboard.TargetProperty="Background">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="Aqua"/>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>
Run Code Online (Sandbox Code Playgroud)

这是Code-Behind:

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    private void MyButton_Click(object sender, RoutedEventArgs e)
    {
        VisualStateManager.GoToState(this, "Blue", true);
    }
}
Run Code Online (Sandbox Code Playgroud)

理论上,这应该在点击时将Button-Color更改为"Aqua",但没有任何反应.

c# xaml visual-studio-2010 visualstatemanager windows-runtime

4
推荐指数
1
解决办法
4928
查看次数

wpf使用VisualStateManager来更改Visibility

我正在努力将一些代码从silverlight转换为WPF,而我的VisualStates无法正常工作.

我使用visualstatemanager来控制某些文本字段的可见性.我没有使用任何过渡来为变化设置动画,我只想让字段在一个状态下折叠,然后在另一个状态下显示.

来自silverlight的Xaml:

<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="LostPasswordStates">
            <VisualState x:Name="LostPassword_Start">
                <Storyboard>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="lbl_UserName" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="txt_UserName" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="txt_UserName" Storyboard.TargetProperty="(TextBox.IsReadOnly)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="False" />
                    </ObjectAnimationUsingKeyFrames>

                </Storyboard>
            </VisualState>
            <VisualState x:Name="LostPassword_Success">
                <Storyboard>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="lbl_UserName" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Collapsed" />
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="txt_UserName" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Collapsed" />
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="btn_Reset" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Collapsed" />
                    </ObjectAnimationUsingKeyFrames>

                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
Run Code Online (Sandbox Code Playgroud)

我得到以下异常:

PresentationCore.dll中出现未处理的"System.Windows.Media.Animation.AnimationException"类型异常

附加信息:无法使用'System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames'为'System.Windows.Controls.TextBox'上的'Visibility'属性设置动画.有关详细信息,请参阅内部异常

所以我的问题是:

如果我不能使用System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames为此,我应该使用什么?

wpf visualstatemanager

4
推荐指数
1
解决办法
3205
查看次数

插入“Label.Text”的 VisualState.Setters 属性时页面崩溃

我有一个带有标签和开关的 .NET MAUI xaml 页面。当我尝试使用VisualState-setters 更改打开/关闭时的标签文本值时,它可以与模拟器和手机调试器模式一起使用,但是当我将其下载到我的 Android 手机中时,尝试打开时页面崩溃!这是重现问题的代码部分:

    <HorizontalStackLayout Grid.Row="2" Grid.Column="0" Margin="5" Spacing="7" BackgroundColor="White" HeightRequest="50">
                                
                <!-- Automatic-Manual -->
                <VerticalStackLayout Margin="2" >
                    <Label x:Name="LblAutoMan" Text="Automatic" VerticalOptions="Start" HorizontalOptions="Center" HeightRequest="20" WidthRequest="65"/>
                    <Switch IsToggled="True" HorizontalOptions="Start" VerticalOptions="Center" HeightRequest="10">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup Name="CommonStates">
                                <VisualState Name="On">
                                    <VisualState.Setters>
                                        <Setter Property="ThumbColor" Value="Green" />
                                        <Setter TargetName="LblAutoMan" Property="Label.Text" Value="Automatic" /> 
                                    </VisualState.Setters>
                                </VisualState>
                                <VisualState Name="Off">
                                    <VisualState.Setters>
                                        <Setter Property="ThumbColor" Value="Red" />
                                        <Setter TargetName="LblAutoMan" Property="Label.Text" Value="Manual" /> 
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Switch>
                </VerticalStackLayout>
               
            </HorizontalStackLayout>
Run Code Online (Sandbox Code Playgroud)

如果我评论两行:<Setter TargetName="LblAutoMan"

有人可以解决这个错误吗?

xaml visualstatemanager .net-maui

4
推荐指数
1
解决办法
527
查看次数

如何知道Silverlight VisualStateManager.GoToState转换何时完成?

我正在使用Silverlight VisualStateManager.GoToState方法将我的控件从一个状态转换到另一个状态.这一切都很好,过渡动画效果很好.但我想知道转换何时完成,以便我可以在我的代码中启动其他操作.是否有事件或其他机制可以用来发现何时完成向另一个州的过渡?

silverlight visualstatemanager

3
推荐指数
1
解决办法
1141
查看次数

在XAML中,VisualStateManager的正确XML命名空间是什么?

我正在尝试重新设置一些ToggleButtons.显然我不能简单地将背景设置为新颜色,因为有一个"控制模板"提供了ToggleButton的视觉行为.所以我需要做的是在XAML中为ToggleButton指定一个替换"ControlTemplate",它提供不同的视觉行为,超出简单的背景颜色.
Q1.它是否正确?


我想从ToggleButton的"默认"controltemplate开始,我从这里抓取,然后修改它.实际上这是Silverlight的默认ControlTemplate,我想,我没有使用Silverlight,我正在使用WPF.但是...... WPF的相应文档页面不包含默认controltemplate的规范.它提供了"a"ControlTemplate,这不是我想要的.
Q2.我不确定我使用Silverlight中的东西是否重要.可以?


在Silverlight示例中,应用于VisualStateManager的vsm的XML名称空间前缀.显然,xml命名空间是

  xmlns:vsm = "clr-namespace:System.Windows;assembly=System.Windows"  
Run Code Online (Sandbox Code Playgroud)

...但在其他地方我读到这个XML命名空间"不再是必需的".

这一切都非常令人困惑.

在Googlespace中,有一些名为"WPF工具包"的引用,我之前已经接触过 - 在WPF V4发布之前将它用于自动完成文本框.我猜测一些WPF工具包的东西被卷入WPF for .NET v4.0,这就是我不再需要指定WPF工具包的原因.
Q3.如果有人能证实这种理解,我会很感激.


好的,现在从ToggleButton的"默认"ControlTemplate开始,我的第一步是编译它,然后再进行任何更改.它没有编译,失败了

c:\ dev ...\ToggleButtonStyle1.xaml(23,14):错误MC3074:标识'VisualStateManager.VisualStateGroups'在XML命名空间中不存在' http://schemas.microsoft.com/winfx/2006/xaml/演讲 '.第23行位置14.

足够清楚.然后我查看了在XAML中指定VisualStateManager的文档.令人困惑的是,它指定了两个xml命名空间,其中一个是我实际使用的命名空间.

在此输入图像描述

Q4嗯,我应该使用哪些?其中一个,我DID使用,它没有用.文档完全不清楚指定TWO XML命名空间的含义.(关上他们的头!)

我在项目文件中引用了PresentationFramework.dll:

  <ItemGroup>
     ....
    <Reference Include="PresentationFramework" />
  </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

我这里没有使用Visual Studio; 我正在使用文本编辑器.我想了解它是如何工作的,而不是要推动的按钮.

感谢您提供的任何帮助.


只是一个评论 - 这似乎非常复杂.我想要做的就是在ToggleButton打开时更改它的颜色.这真的不应该是这么复杂.

wpf xaml visualstatemanager

3
推荐指数
1
解决办法
7977
查看次数