【发布时间】:2014-05-21 04:09:49
【问题描述】:
我在 XAML 中有一个 ListView 控件,其中包含由以下代码 (WinRT C#) 设置样式的项目。 但我无法显示“path_2”,如下图所示。
如何在 WinRT XAML 中向 ListView 添加多个 Shapes.Path?
[MainPage.xaml.cs]
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Shapes;
namespace AppListViewPath
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
object o;
Application.Current.Resources.TryGetValue("PathCustomStyle", out o);
Path path_1 = new Path()
{
Style = (Style)o
};
Path path_2 = new Path()
{
Style = (Style)o
};
this.listView_path.Items.Add(path_1); // show
this.listView_path.Items.Add(path_2); // doesn't show...
}
}
}
[App.xaml]
<Application
x:Class="AppListViewPath.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppListViewPath"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="PathCustomStyle" TargetType="Path">
<Setter Property="Data" Value="M95,15 C95,20 95,20 95,20"/>
<Setter Property="Width" Value="200"/>
<Setter Property="Height" Value="200"/>
<Setter Property="Stroke" Value="Red"/>
<Setter Property="Stretch" Value="Fill"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
[MainPage.xaml]
<Page
x:Class="AppListViewPath.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppListViewPath"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<ListView x:Name="listView_path"/>
</Grid>
</Page>
【问题讨论】:
标签: c# xaml windows-runtime microsoft-metro winrt-xaml