以编程方式在ScatterViewItem控件中插入文本 [英] Insert text inside a ScatterViewItem Control Programmatically
问题描述
Microsoft始终提供简单的解决方案。他们试图避免我们的问题和复杂的问题。
Microsoft always provides easy solution. They try to avoid our questions and complex problems.
无论如何,有一个解决方案,其中ScatterViewItem是以编程方式创建的。
Anyway, there is a solution where ScatterViewItem is created programmatically.
SurfaceWindow1.xaml
<s:SurfaceWindow
x:Class="AddScatterViewItem.SurfaceWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.microsoft.com/surface/2008"
Title="AddScatterViewItemByCode">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<s:SurfaceButton Name="Add" Content="Add" Click="Add_Click"/>
</StackPanel>
<s:ScatterView Name="MainScatterView" Grid.Row="1"/>
</Grid>
</s:SurfaceWindow>
SurfaceWindow1.xaml.cs
SurfaceWindow1.xaml.cs
private void Add_Click(object sender, RoutedEventArgs e)
{
Label label = new Label();
label.Content = String.Format("Item #{0}", MainScatterView.Items.Count + 1);
MainScatterView.Items.Add(label);
}
But I do not want to add pre defined Label Content. When I will click on the button, I want ScatterViewItem where I can insert my desired text inside it during run time. How can I do it?
推荐答案
嗨Sazzadur
Hi Sazzadur
我可以想象几种方法首先将你的文本与某种可观察对象绑定,也许继承自
INotifyPropertyChanged ,具体取决于您的文字将在之前和之后更改的绑定类型 你想知道!
without trying i can imagine a couple of ways first of all a to bind your text with some sort of observable object, maybe inheriting from INotifyPropertyChanged, depending on the binding type your text will change back and forward when you whant!
希望这会有所帮助
这篇关于以编程方式在ScatterViewItem控件中插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!