[英]How can I create this kind of model on Visual Studio WPF?[TreeList to TextBox]
Oh hi folks, I'm a newbie on the C# world, but I really wanted to know if it's possible to do and if possible how to.哦,大家好,我是 C# 世界的新手,但我真的很想知道是否可以这样做以及如何做。 Basically is a program model, with a Datagridview in which each cell would contain a Treelist that leads to a box of selectable text.
基本上是一个程序模型,带有一个 Datagridview,其中每个单元格都包含一个 Treelist,它指向一个可选文本框。 I tried to find this specific model everywhere on the internet but had no success.
我试图在互联网上到处找到这个特定的模型,但没有成功。
Model : ProgramModel.exe模型: ProgramModel.exe
Sorry if the comic crap annoyed you.对不起,如果漫画废话惹恼了你。
Hello I think a ListView control may be better use in this case, you may use a DataTemplate to style the ListView and tell it how to to display the items, first add these XAML codes:您好,我认为在这种情况下使用 ListView 控件可能会更好,您可以使用 DataTemplate 来设置 ListView 的样式并告诉它如何显示项目,首先添加这些 XAML 代码:
<ListView x:Name="MainListView" HorizontalAlignment="Center" VerticalAlignment="Center">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<Border BorderBrush="Black" BorderThickness="3,3,3,3" Margin="1,0,0,0" MinWidth="200">
<TextBlock Text="{Binding Path=TxtType}" Margin="10,0,0,0"></TextBlock>
</Border>
<TreeView>
<Border BorderBrush="Black" BorderThickness="3,3,3,3" Margin="-20,0,0,0" MinWidth="200">
<TreeViewItem Header="smalpptext">
<TreeViewItem.Items>
<TextBox Text="{Binding Path=SmalPPTxt}" IsReadOnly="True"></TextBox>
</TreeViewItem.Items>
</TreeViewItem>
</Border>
<Border BorderBrush="Black" BorderThickness="3,3,3,3" Margin="-20,0,0,0" MinWidth="200">
<TreeViewItem Header="largepptext">
<TreeViewItem.Items>
<TextBox Text="{Binding Path=LargePPTxt}" IsReadOnly="True"></TextBox>
</TreeViewItem.Items>
</TreeViewItem>
</Border>
</TreeView>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
After we have the ListView ready we will need to populate it with data, we can use an ObservableCollection, add these C# codes:在我们准备好 ListView 之后,我们需要用数据填充它,我们可以使用 ObservableCollection,添加这些 C# 代码:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
AddText();
MainListView.ItemsSource = StringList;
}
ObservableCollection<PPStrings> StringList = new ObservableCollection<PPStrings>();
private class PPStrings
{
public string TxtType { get; set; }
public string SmalPPTxt { get; set; }
public string LargePPTxt { get; set; }
}
private void AddText()
{
PPStrings p1 = new PPStrings();
p1.TxtType = "Text Type";
p1.SmalPPTxt = "LOLXD a dork with small pp.";
p1.LargePPTxt = "A dork with large PP.";
PPStrings p2 = new PPStrings();
p2.TxtType = "Text Type";
p2.SmalPPTxt = "LOLXD a wierdo with small pp.";
p2.LargePPTxt = "A wierdo with large PP.";
PPStrings p3 = new PPStrings();
p3.TxtType = "Text Type";
p3.SmalPPTxt = "HaHa a dork with small pp.";
p3.LargePPTxt = "Haha A dork with large PP.";
StringList.Add(p1);
StringList.Add(p2);
StringList.Add(p3);
}
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.