簡體   English   中英

將靜態類屬性綁定到文本框

[英]Binding static class property to textbox

我想將textbox綁定到靜態類的屬性。 我希望這是雙向綁定。 我的靜態課堂是這個(修剪):

public static class ocrVar
{
    static ocrVar()
    {  
        MeterNumber = new Element();
    }
}

Element類看起來像這樣(修剪):

public class Element
    {

        public List<string> Value { get; set; }

        public Element()
            : this(new List<string>())
        {
        }
        public Element(List<string> value)
        {
        Value = value;
        }
    }

如果我想取一個TextBox並將其綁定到ocrVar.MeterNumber.Value [0],有什么方法可以做到這一點?

由於它是靜態類,並且您想要執行雙向綁定 ,因此您已經提供了路徑並提供了一個非靜態類作為技巧,然后使用綁定

在你的情況下

<Window.Resources>
    <local:ocrVar x:Key="ocrVarManager"/>
</Window.Resources>

<TextBox Text="{Binding Source={StaticResource ocrVarManager}, Path=MeterNumber.Value[0]}"/>

您可以參考綁定到靜態屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM