该TextBlock元素处理LineHeight得很好,允许文本完全显示,而不会剪切.但是,我想将其更改TextBox为便于编辑文本,这是我的麻烦开始的地方.
在TextBlock显示文字是这样的:
在TextBox显示文字是这样的:
我试图摆弄ClipToBounds和Clip属性,但它只在元素内剪辑,不会扩展到边界之外.
LineHeight需要将该属性设置为低以调节线之间的差距,因此不能进行更改.
我也尝试过Padding,但它只是这样做
如果这是唯一的解决方案,那我就会走开,聆听按键并相应地更改文本,但这似乎是很多工作,我不认为这是一个很好的解决方案,所以这是我的浓缩题:
如何使TextBox剪辑文本尽可能不像TextBlock它一样?
private static Style GetFontTextBlock()
{
var style = new Style();
style.Setters.Add(new Setter(TextBlock.LineStackingStrategyProperty, LineStackingStrategy.BlockLineHeight));
style.Setters.Add(new Setter(TextBlock.IsHyphenationEnabledProperty, true));
style.Setters.Add(new Setter(TextBlock.TextWrappingProperty, TextWrapping.Wrap));
style.Setters.Add(new Setter(Control.BorderBrushProperty, null));
return style;
}
public static Style GetHeadline()
{
// ApplyFont sets the Control.FontFamilyProperty to Geogrotesque Condensed Regular.
// It's a purchased font so I can't supply it, …Run Code Online (Sandbox Code Playgroud) 关于Casting泛型类型"as T",同时强制执行T的类型
并通过以下示例
private static T deserialize<T>(string streng) where T : class
{
XmlSerializer ser = new XmlSerializer(typeof(T));
StringReader reader = new StringReader(streng);
return ser.Deserialize(reader) as T;
}
Run Code Online (Sandbox Code Playgroud)
和
private static T deserialize<T>(string streng)
{
XmlSerializer ser = new XmlSerializer(typeof(T));
StringReader reader = new StringReader(streng);
return (T)ser.Deserialize(reader);
}
Run Code Online (Sandbox Code Playgroud)
我习惯于进行object as Type演员表演,所以当我发现我不能那样做时,我有点困惑T.然后我找到了上面的问题,并找到了as T编译器错误的解决方案.
但是为什么where T : class在使用object as T时需要而不是在使用时(T)object?两种铸造物体的方式之间的实际差异是什么?
DotNetZip有一个奇怪的问题,我似乎无法找到解决方案.我现在已经搜索了几个小时而且我找不到任何关于此的内容,所以这里有.
var ms = new MemoryStream();
using (var archive = new Ionic.Zip.ZipFile()) {
foreach (var file in files) {
// string byte[]
var entry = archive.AddEntry(file.Name, file.Data);
entry.ModifiedTime = DateTime.Now.AddYears(10); // Just for testing
}
archive.Save(ms);
}
return ms.GetBuffer();
Run Code Online (Sandbox Code Playgroud)
我需要添加修改时间,这是非常关键的,但是现在我只有一个虚拟时间戳.
当我用WinRAR打开文件时,它会显示"意外的归档结束".每个单独的文件都有校验和00000000,WinRAR说"存档格式未知或已损坏".我可以修理它,它可以减少20%的尺寸并使一切正常.但这并不是真的有用..
当我在添加所有条目后创建断点时,我可以看到zip.Entries所有条目都具有相同的错误CRC,但所有数据似乎都存在.所以它不应该是我保存存档的问题.
我在其他地方使用我的文件集没有问题,这增加了DotNetZip很奇怪.好吧,或者我误解了一些东西:)