【问题标题】:Listviewitem trims contentListviewitem 修剪内容
【发布时间】:2015-02-27 14:56:32
【问题描述】:

我似乎无法解决这个问题(WPF/c#)。

我有 2 个窗口,父母和孩子。

在父窗口中有一个带有项目的 listviewitem。 在子窗口中有一个文本框可以选择该项目的内容(一个字符串)和“创建”按钮以确认文本框中的字符串进入 listviewitem,然后子窗口关闭。

图片:enter link description here

但是,通常当我单击创建时,文本会被修剪。我无法复制它,甚至不能使用相同的名称,这很奇怪。

图片:enter link description here

我正在使用列表视图,因为它必须看起来与包含许多项目的列表视图完全相同。

这是“创建”按钮的代码。

//Here I put the name into the listview item and into a setting variable for future use.
myparent.lstbcostum.Content = txtname.Text;
Properties.Settings.Default.CostumName = txtname.Text;
                                                       
//other code for saving other stuff
 var savepath = System.AppDomain.CurrentDomain.BaseDirectory + "\\Beats\\Costum";
FileInfo myFile = new FileInfo(savepath + "A.wav");
myFile.Attributes = FileAttributes.Normal;
File.Copy(Globals_Costum.Beata, savepath + "A.wav", true);
myFile = new FileInfo(savepath + "B.wav");
myFile.Attributes = FileAttributes.Normal;
File.Copy(Globals_Costum.Beatb, savepath + "B.wav", true);

//other code for saving other stuff and saving settings
Properties.Settings.Default.CostumFlag = true;
myparent.lstbcostum.IsEnabled = true;
Properties.Settings.Default.Save();
                                                             
//Closing child                                              this.Close();                                               WpfApplication1.Window3.Globals_Beat.frmCostumOpened = false;

【问题讨论】:

  • 您可以在您的问题中添加一些代码 sn-ps 吗?
  • 嗨,我添加了“创建”按钮代码。

标签: c# wpf listview


【解决方案1】:

在列表框/列表视图的 WPF XAML 模板中,您可能有一个文本块。确保您将该文本块元素的水平对齐设置为“拉伸”,或者尝试将列表框/列表视图的水平内容对齐设置为“拉伸”。看起来里面的任何东西都有固定的宽度。

一开始很困惑,因为从屏幕截图中看起来它正在用感叹号代替 5..

【讨论】:

  • 我试过了,但它已经设置为拉伸,所以我尝试了其他对齐方式,但有时它仍然会切断文本。我什至每次在将文本重置宽度后都尝试过,但没有。
  • 你能发布相关的 XAML 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多