でテキストボックスに透かしがClearAllをを組み合わせる: Watermark/hint text/placeholder TextBox in WPFは私のために働くために透かしを得るために多くの方法を試した後、私は最終的に1は、このページに@Beejによって変更見つかっWPF
私はそれが私のプロジェクトに置かれました、 1つの例外を除いて、正常に動作します。私はタブコントロールの各タブに複数のテキストボックスを持っています。下部には、タブ上のすべてのテキストボックスをクリアするクリアボタンがあります。クリアボタンはうまくいきますが、透かしはうまく動作しますが、一緒に動作させることはできません。ウィンドウにウォーターマークが挿入され、クリアボタンを押すとすべてのボックスがクリアされますが、テキストボックス内を移動するまでウォーターマークが再表示されません(それぞれがフォーカスを得たり消えたりします)。 、ボタンのMouseUpイベントのShowWatermark関数へのメソッド呼び出しを配置するなど、何も機能していません...ヘルプ!別々のクラスファイルで
public void ClearTextBoxes()
{
ChildControls ccChildren = new ChildControls();
foreach (object o in ccChildren.GetChildren(rvraDockPanel, 2))
{
if (o.GetType() == typeof(TextBox))
{
TextBox txt = (TextBox)o;
txt.Text = "";
}
if (o.GetType() == typeof(DigitBox))
{
DigitBox digit = (DigitBox)o;
digit.Text = "";
}
if (o.GetType() == typeof(PhoneBox))
{
PhoneBox phone = (PhoneBox)o;
phone.Text = "";
}
if (o.GetType() == typeof(DateBox))
{
DateBox date = (DateBox)o;
date.Text = "";
}
if (o.GetType() == typeof(TextBoxWatermarked))
{
TextBoxWatermarked water = (TextBoxWatermarked)o;
water.Text = "";
}
}
}
class ChildControls
{
private List<object> listChildren;
public List<object> GetChildren(Visual p_vParent, int p_nLevel)
{
if (p_vParent == null)
{
throw new ArgumentNullException("Element {0} is null!", p_vParent.ToString());
}
this.listChildren = new List<object>();
this.GetChildControls(p_vParent, p_nLevel);
return this.listChildren;
}
private void GetChildControls(Visual p_vParent, int p_nLevel)
{
int nChildCount = VisualTreeHelper.GetChildrenCount(p_vParent);
for (int i = 0; i <= nChildCount - 1; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(p_vParent, i);
listChildren.Add((object)v);
if (VisualTreeHelper.GetChildrenCount(v) > 0)
{
GetChildControls(v, p_nLevel + 1);
}
}
}
}
ChildControlsクラスの両方と(上記のリンクから)TextboxWatermarkedクラスされています
これは私が使用しているクリアボタン方式です。
ありがとう、完璧に働いた! –