- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如果字符串相同,则不会打印/绑定(bind)/发布到 WPF 表单文本框中的 View 。例如,如果我使用 random 来生成我正在制作成字符串的字节数组,那么它确实会发布到 View 中。
这是 View 绑定(bind)到的我的 ViewModel:
public class ViewModel : INotifyPropertyChanged
{
public StringBuilder Data
{
get { return _data; }
set
{
_data = value;
OnPropertyChanged("Data");
}
}
private Service service = new Service();
private StringBuilder _data;
public ViewModel()
{
service.BytesArrived += ServiceOnBytesArrived;
ThreadPool.QueueUserWorkItem(starupService);
}
private void starupService(object state)
{
service.Start();
}
private void ServiceOnBytesArrived(byte[] bytes)
{
var sBuilder = new StringBuilder();
foreach (var b in bytes)
{
sBuilder.Append(b.ToString() + ", ");
}
Data = sBuilder;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
这是为我打印字节的服务(如果使用随机代替则工作正常:
public class Service
{
public void Start()
{
var random = new Random(DateTime.Now.Minute);
while (true)
{
//random.NextBytes(bytes);
for (int i = 0; i < 10; i++)
{
bytes[i] = 0;
Thread.Sleep(10);
}
//Thread.Sleep(100);
BytesArrived(bytes);
}
}
private byte[] bytes = new byte[10];
public event Action<byte[]> BytesArrived;
}
这是我正在使用的使用 AppendText 的依赖属性:
public static class TextBoxAttachedBehaviors
{
#region AppendText Attached Property
public static string GetAppendText(TextBox textBox)
{
return (string)textBox.GetValue(AppendTextProperty);
}
public static void SetAppendText(
TextBox textBox, string value)
{
textBox.SetValue(AppendTextProperty, value);
}
public static readonly DependencyProperty AppendTextProperty =
DependencyProperty.RegisterAttached(
"AppendText",
typeof(string),
typeof(TextBoxAttachedBehaviors),
new UIPropertyMetadata(null, OnAppendTextChanged));
private static void OnAppendTextChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
if (e.NewValue == null)
return;
TextBox textBox = d as TextBox;
textBox.AppendText(e.NewValue.ToString());
}
#endregion
}
XAML:
<TextBox attachedBehaviors:TextBoxAttachedBehaviors.AppendText="{Binding TextBoxAppend}"/>
如果您有 ReSharper,它将提供替换 namespace 的功能,例如attachedBehaviors:
带有实际附加行为的类链接,在我的例子中是 xmlns:attachedBehaviors="clr-namespace:Support.NetworkMonitor.AttachedBehaviors"
。
最佳答案
DependencyProperties 在触发通知之前比较它们的旧值和新值,并且仅在确实存在差异时才触发它。解决方案很简单:在设置字符串之前将 AppendText 设置为 null,例如
public StringBuilder Data
{
get { return _data; }
set
{
_data = null;
OnPropertyChanged("Data");
_data = value;
OnPropertyChanged("Data");
}
}
关于c# - 为什么当字符串相等时此 AppendText 依赖属性不打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13631633/
我的文本框有问题。 我有一个代表 GUI 线程的类和一个用于执行一些网络工作的工作线程的类,然后必须将日志添加到 GUI 线程中的文本框,以便您可以看到后台发生的事情。 但是,我遇到的问题是 GUI
我尝试了以下方法让我的文本框文本自动滚动: 我使用的步骤非常简单: 将文本框拖到表单上。 将文本框更改为多行。 添加垂直滚动。 使用 AppendText() 向文本框添加文本。 尽管尝试了此处提到的
如果字符串相同,则不会打印/绑定(bind)/发布到 WPF 表单文本框中的 View 。例如,如果我使用 random 来生成我正在制作成字符串的字节数组,那么它确实会发布到 View 中。 这是
我是 Kotlin 的新手,但我有很强的 Java 背景(Java 是我的日常工作)。我喜欢 Kotlin 中的一些快捷函数。其中一个重要的是 File.appendText()。在我看来,这非常方便
我正在开发一个 JavaFX 终端应用程序,它可以高速显示来自串行端口的文本。我正在使用 TextArea 控件来显示和管理文本。对于来自串行端口的每个文本 block ,我使用appendText
我有一个文本(有多行),需要将其放入 wxPython TextCtrl 中。 问题是其中一些行包含无法打印的字符。 我的解决方案是使用 AppendText,并 try catch 有问题的行。 当
我在 C++ 和 C# 之间有一个简单的客户端/服务器通信,其中 C# 程序向 C++ 发送一个字符串。字符串的发送分 3 个阶段完成。发送字符串长度-->发送字符串长度-->发送字符串。出于调试目的
我在 winforms 对话框(在 .net4.5 上)中有一系列按钮,它们将文本片段附加到名为 FieldDescription 的文本框,如下所示: private void SnippetBut
这个问题在这里已经有了答案: javafx 8 compatibility issues - FXML static fields (1 个回答) 关闭 8 年前。 我在此项目中使用 JavaFX
我目前正在按照 Geekpedia 上的精彩教程创建我自己的 Chat Client和 Chat Server . 将客户端连接到服务器工作正常,但我在聊天记录中显示文本时遇到了一些问题。 显示的第一
WPF 的初学者,请多多包涵。 在继续之前,我构建了一个概念验证应用程序。我决定先尝试使用 WPF 构建它。 这是场景: 我有: a View=CustomerView(带有“购买产品”按钮的用户控件
我是 Python 新手,所以我也是 wxPython 新手。我只是想知道这些 wx.TextCtrl 函数之间是否有任何区别。这个迷你代码显示了三倍相同的输出。如果没有差异,这些功能是否有历史原因?
我正在尝试使用 返回的 DateTimeFormatter 来解析表示具有 IsoField.QUARTER_OF_YEAR 的 LocalDate 值的文本DateTimeFormatterBuil
我正在使用django-crispy-forms渲染 django 中模型的形式。 django-crispy-forms 已经与 Twitter Bootstrap 很好地集成并为 AppdedTe
所以最近我们强制我们的应用程序在 IE9 模式下运行,从那时起,WatiN typetext、AppendText 与 TriggerClientChange(如下所示)结合使用就不再触发页面上的 J
为了使用 File.CreateText() 和 File.AppendText() 你必须: 通过调用这些方法之一打开流 写消息 关闭流 处理流 为了使用 File.AppendAllText()
这两种方法有什么区别? 一个比另一个更有效率吗? 我在想 AppendText() 可能使用类似于 StringBuilder 的方法,即它使用自己的缓存而不是每次都创建和附加一个新字符串,是这样吗?
我正在使用多行文本框,但出现了我无法完全解释的行为。我用 textbox.AppendText("line \n"); 向文本框追加新行。当使用这个 3 次时,我得到了 line line line
表格: class StartEndDateEpayOperatorsForm(forms.Form): ... def __init__(self, *args, **kwargs)
我必须将数千行动态生成的行写入文本文件。我有两个选择,哪个比另一个消耗更少的资源并且速度更快? A.使用 StringBuilder 和 File.WriteAllText StringBuilder
我是一名优秀的程序员,十分优秀!