Xaml UWP可视状态管理器不';看不到数据模板的内容
我的页面结构如下所示Xaml UWP可视状态管理器不';看不到数据模板的内容,xaml,uwp,visualstatemanager,uwp-xaml,adaptive-design,Xaml,Uwp,Visualstatemanager,Uwp Xaml,Adaptive Design,我的页面结构如下所示 <ScrollViewer VerticalScrollBarVisibility="Auto"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="VisualStateGroup"> <VisualState x:Name="VisualStateNarrow">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="VisualStateNarrow">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1"/>
</VisualState.StateTriggers>
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateWide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="800"/>
</VisualState.StateTriggers>
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Pivot x:Name="PivotPlatform" Margin="0" ItemsSource="{Binding PivotItems}" Grid.Row="2">
<Pivot.HeaderTemplate>
<DataTemplate>
<StackPanel Height="0" Width="0">
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
</Pivot.HeaderTemplate>
<Pivot.ItemTemplate>
<DataTemplate>
<Grid xmlns:uwp="using:AmazingPullToRefresh.Controls">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<uwp:PullToRefreshAdorner.Extender>
<uwp:PullToRefreshExtender RefreshRequested="PullToRefreshExtender_RefreshRequested" />
</uwp:PullToRefreshAdorner.Extender>
<RelativePanel x:Name="contentPanel" Grid.Row="0" Margin="10 -30 10 10">
<TextBlock Name="titleTB" Text="{Binding Title}" FontSize="12"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignTopWithPanel="True"/>
<TextBlock Name="totalTB" Text="{Binding Total}" FontSize="18"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below="titleTB" />
<ProgressBar Name="progressBar" Value="{Binding ProgressValue}" Width="100" Foreground="{StaticResource currentThemeColor}"
RelativePanel.AlignLeftWithPanel="True" RelativePanel.Below="totalTB"
Margin="0 5 0 0"/>
<TextBlock Name="dateTB" Text="{Binding Date}" FontSize="16"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignTopWithPanel="True" />
</RelativePanel>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<Charting:Chart Grid.Row="1" x:Name="LineChart"
Margin="10" >
<Charting:LineSeries Title="" IndependentValuePath="Name" DependentValuePath="Amount"
IsSelectionEnabled="False" ItemsSource="{Binding Result}" />
</Charting:Chart>
</ScrollViewer>
</Grid>
</DataTemplate>
</Pivot.ItemTemplate>
</Pivot>
当我将dateTBtextblock的setter添加到VisualState.Setters中以将其移动到相对面板的左侧时,我得到一个错误消息:
动画试图修改名为“dateTB”的对象,但在页面中找不到此类对象
添加setter的代码为:
<Setter Target="dateTB.(RelativePanel.AlignLeftWithPanel)" Value="True"/>
有没有一种方法可以通过具有此页面结构的可视状态管理器来控制此文本块?这是一个名称范围的问题,所有XAML UI框架都有此问题。您的VSM位于
用户控件
或页面
的名称范围内,文本块
位于数据模板
中
Romasz将VSM放在
数据模板中的解决方案将您需要的所有内容放在一个名称范围内,这是解决此问题的最佳解决方案。这是一个名称范围的问题,所有XAML UI框架都有此问题。您的VSM位于用户控件
或页面
的名称范围内,文本块
位于数据模板
中
Romasz解决问题的方法是将VSM放在数据模板中
将您需要的所有内容放在一个名称范围内,这是解决此问题的最佳方法。您的文本块在数据模板中,这就是为什么会出现异常。@Romasz是的,就是这种情况。但是,当我删除DataTemplate时,我得到一个错误,即ItemTemplate不支持类型Grid。你知道如何制作一个可以从VisualStateManager中看到的ItemTemplate吗?你是否尝试过将VisualStateManager放在数据模板中的网格下?@Romasz我成功了。感谢您的评论,这是因为DataTemplate,我发现我必须将DataTemplate的内容放在UserControl中,然后将VisualStateManager放在DataTemplate的网格中。感谢您的支持。您的文本块在DataTemplate中,这就是为什么会出现异常。@Romasz是的,就是这样。但是,当我删除DataTemplate时,我得到一个错误,即ItemTemplate不支持类型Grid。你知道如何制作一个可以从VisualStateManager中看到的ItemTemplate吗?你是否尝试过将VisualStateManager放在数据模板中的网格下?@Romasz我成功了。感谢您的评论,这是因为DataTemplate,我发现我必须将DataTemplate的内容放在UserControl中,然后将VisualStateManager放在DataTemplate的网格中。感谢您的支持。如果我有一个数据模板
,它的内容
是一个自定义的用户控件
(基本上是一个列表视图
)。并且ListView
具有一个Header
由scroll Header
组成。而ScrollHeader
是控件的网格。我想更改网格中控件的可视状态。我应该把VSM放在哪里?我把它放在滚动标题中,但它不起作用。你应该问你自己的问题,并提供更多细节,但同样应该适用-如果你需要视觉状态-你可能应该创建一个单独的控件,并将VSM放在根面板上(网格
),如果我有数据模板
,该怎么办,它的内容
是一个自定义的用户控件
(基本上是一个列表视图
)。而列表视图
有一个标题
,由滚动标题
组成。而ScrollHeader
是控件的网格。我想更改网格中控件的可视状态。我应该把VSM放在哪里?我把它放在滚动标题中,但它不起作用。你应该问你自己的问题,并提供更多细节,但同样应该适用-如果你需要视觉状态-你可能应该创建一个单独的控件,并将VSM放在根面板上(网格
)