我是 WPF 的新手,我有 WinForms 的背景,我正在尝试实现一个 coverflow,但我并不完全理解这个例子,据我所知,我将路径添加到我的图像到 StringCollection
。
这就是我现在拥有的:
public MainWindow()
{
InitializeComponent();
elementFlow1.Layout = new CoverFlow();
StringCollection itemssource = new StringCollection();
itemssource.Add(@"Images\1.png");
itemssource.Add(@"Images\2.png");
elementFlow1.SelectedIndex = 0;
elementFlow1.ItemsSource = itemssource;
}
我在 XAML 中定义了 ElementFlow
,如下所示:
<fluidkit:ElementFlow Grid.Row="1" Height="194" Name="elementFlow1" VerticalAlignment="Top" Width="503" />
你瞧,当我运行它时,没有任何反应。
有人可以解释一下我应该如何使用 ElementFlow
吗?这个例子并没有很好地“解释”它。
最佳答案
您错过了一个关键步骤。 ElementFlow
控件显示 UIElement
,而不是字符串。您有一个字符串列表,其中包含图像文件的逻辑文件位置。现在您需要将该字符串集合转换为 DataTemplate
集合。如果查看示例 xaml 文件,您将看到以下部分:
<DataTemplate x:Key="TestDataTemplate"
DataType="{x:Type sys:String}">
<Border x:Name="ElementVisual"
Background="White"
Padding="5"
BorderThickness="5"
BorderBrush="LightGray"
Grid.Row="0">
<Image Source="{Binding}"
Stretch="Fill" />
</Border>
</DataTemplate>
该部分实质上采用字符串输入并将其转换为 DataTemplate
。这是通过将 ItemTemplate
属性设置为此 DataTemplate
资源来完成的。
在 XAML 中而不是在代码隐藏中操作此控件可能会更好。这样事情就容易多了(无论如何在我看来)。
希望这对您有所帮助。
关于c# - 如何使用 ElementFlow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14167322/