有没有办法在标准的Winforms listview控件中显示多行文本?
谢谢,凯末尔
在WPF中,我可以添加任何UI到ListBoxItem通过提供的S ListBox有ItemTemplate:
<ListBox ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" BorderBrush="Gray" CornerRadius="8" Padding="4,0,4,0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<CheckBox Grid.Column="1" Content="Is Active Customer" IsChecked="{Binding IsActive}"/>
<Label Content="Id:" Grid.Row="1" HorizontalAlignment="Right"/>
<Label Content="Name:" Grid.Row="2" HorizontalAlignment="Right"/>
<TextBox Text="{Binding Id}" Grid.Row="1" Grid.Column="1"/>
<TextBox Text="{Binding Name}" Grid.Row="2" Grid.Column="1"/>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
结果是:

有没有办法在Windows窗体中实现相同的功能?
编辑:
1 -有什么办法,以实现在Windows窗体一样,同时保持separation of concerns之间View和Application Logic以这样的方式,如果我后来想完全重新定义View,我就不必重构整个应用程序?
2 - winforms是否支持数据绑定,使得我的每一个ListBoxItems都可以绑定到一个复杂的Entity,最终包括从Model数据到UI数据的中间类型转换,然后返回,这样我就不必写入大量的样板代码填充视图,然后将UI值传回模型以便保存? …
我有一些包含换行符的字符串,我想在应用这些字符串的每个 ListBox 项中保留这种格式。
有没有办法做到这一点?
谢谢
所以我一直在疯狂地为我的String.Join打印输出添加新行,但似乎不可能或我做错了什么?我已经尝试过使用"/n/r",Enivrorment.NewLine以及创建一个类也创建一个新的行
列表框我也试图打印出来
ListBox1.Items.Add("Calories to lose 0.5kg per week: " +
string.Join(Environment.NewLine + "Calories to lose 1kg per week:",
bc.LoseOrGainWeightCalories(bc.MaintainWightCalories(), true)));
Run Code Online (Sandbox Code Playgroud)
拜访这堂课:
public string[] LoseOrGainWeightCalories(double weight, bool lose) {
string[] array = new string[2];
double LoseGainWeight = this.weight;
if(lose==true) {
array[0] = Convert.ToString(LoseGainWeight - 500);
array[1] = Convert.ToString(LoseGainWeight - 1000);
} else {
array[0] = Convert.ToString(LoseGainWeight + 500);
array[1] = Convert.ToString(LoseGainWeight + 1000);
}
return array;
}
Run Code Online (Sandbox Code Playgroud)
电流输出图片:
