我在我的silverlight 4應用程序中定義了2個可視狀態的ChildWindow。VisualStateManager.GotoState在ChildWindow中不工作
視覺狀態做我想要的,當我在Blend中預覽它們,但是當我調用ViewStateManager.GotoState時,它返回false並且不轉換視覺狀態。
繼承人我的XAML。 Appologies的長度...
<controls:ChildWindow xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
xmlns:Controls1="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:Behaviors="clr-namespace:Civica.UI.Common.Behaviors;assembly=Civica.UI.Common"
xmlns:Controls2="clr-namespace:Civica.UI.Common.Controls;assembly=Civica.UI.Common"
xmlns:Helpers="clr-namespace:Civica.UI.Common.Helpers;assembly=Civica.UI.Common"
x:Class="Civica.UI.Administration.Staff.StaffSearch.StaffSearchView"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
Width="800"
Helpers:VisualStateHelper.VisualStateName="{Binding Path=VisualStateName}">
<controls:ChildWindow.Title>
<TextBlock Text="Staff Search" Margin="0,4" TextWrapping="Wrap" />
</controls:ChildWindow.Title>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SearchResultsStateGroup">
<VisualState x:Name="NoSearchResults">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="border">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Duration="0" To="0.3" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="dataGrid" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Margin="0,0,0,7">
<Grid.RowDefinitions>
<RowDefinition Height="Auto "/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Controls:Label Content="Search for:" Margin="0,0,10,0"/>
<Controls2:CommandTextBox Grid.Row="1" Grid.Column="1"
ImageHeight="16" ImageWidth="16"
Text="{Binding CurrentSearchTerm, Mode=TwoWay}"
Command="{Binding SearchCommand}"
CommandParameter="{Binding CurrentSearchTerm}"
Image="/Civica.UI.Common.Images;component/Resources/Icons/16x16/RGB/icon-search-tiny.png" />
</Grid>
<Grid Grid.Row="1">
<Controls1:DataGrid x:Name="dataGrid" AutoGenerateColumns="False"
IsReadOnly="True"
AreRowGroupHeadersFrozen="True"
CanUserResizeColumns="True"
ItemsSource="{Binding CurrentSearchResults}"
SelectedItem="{Binding CurrentlySelectedSearchResult, Mode=TwoWay}"
VerticalScrollBarVisibility="Auto"
Height="300">
<Interactivity:Interaction.Behaviors>
<Behaviors:DataGridDoubleClickBehaviour DoubleClickCommand="{Binding SelectSearchResultCommand}"
CommandParameter="{Binding CurrentlySelectedSearchResult}"/>
</Interactivity:Interaction.Behaviors>
<Controls1:DataGrid.Columns>
<Controls1:DataGridTextColumn Header="Name" Binding="{Binding DisplayName}" IsReadOnly="True" />
<Controls1:DataGridTextColumn Header="Phone" Binding="{Binding TelephoneNumber}" IsReadOnly="True" />
<Controls1:DataGridTextColumn Header="Location" Binding="{Binding Location}" IsReadOnly="True" />
</Controls1:DataGrid.Columns>
</Controls1:DataGrid>
<TextBlock x:Name="textBlock" Text="No Results Found" Foreground="Black" Opacity="1" FontSize="13" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="30" Visibility="Collapsed"/>
<Border x:Name="border" Background="Black" Opacity="0.3" Visibility="Collapsed"/>
</Grid>
</Grid>
</controls:ChildWindow>
VisualStateHelper.VisualStateName僅僅是一個附加屬性,當值改變調用VisualStateManager。該財產的實施可能不是問題,因爲它在別處運作。
private static void OnVisualStateNameChanged(object sender, DependencyPropertyChangedEventArgs args)
{
var visualStateName = (string)args.NewValue;
var control = sender as Control;
if (control == null)
{
throw new ArgumentException(Resources.VisualStateHelperSenderNotAControlErrorMessage, "sender");
}
VisualStateManager.GoToState(control, visualStateName, true);
}
該鏈接不指向預期的地方了。 – Murven 2013-11-15 22:25:20