单击按钮时更新装饰器中的文本

发布于 2024-11-02 13:58:32 字数 1326 浏览 5 评论 0原文

我创建了自定义装饰器,用灰色画布覆盖我的主窗口,并在中心放置一个文本块,以在我在其他窗口上工作时显示一些状态文本。

我目前正在做的是从我的资源中获取所需的 adornerElement(即带有文本块的画布)并将其传递给我的视图构造函数中的装饰器,如下所示 -

 ResourceDictionary reportResourceDictionary = App.LoadComponent(new Uri("Resources/ReportResources.xaml", UriKind.Relative)) as ResourceDictionary;
 UIElement adornerElement = reportResourceDictionary["RefreshingReportAdorner"] as UIElement;
 mainWindowBlockMessageAdorner = new MainWindowBlockMessageAdorner(mainPanel, adornerElement);

但我想在某些情况下更新文本块中的文本,例如如果我单击其他窗口中的某些按钮但如何动态更新文本?

资源文件中的装饰器元素 -

<Grid x:Key="RefreshingReportAdorner">
        <Rectangle Fill="Gray"
                   StrokeThickness="1"
                   Stroke="Gray"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Stretch"/>
        <Border BorderBrush="Black"
                BorderThickness="2"
                Background="White"
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
            <TextBlock i18n:LanguageManager.VisualId="6"
                       Text="Some Text(Update dynamically)"                       
                       Padding="15,10,15,10"/>
        </Border>
    </Grid>

如果需要其他代码或方法,请告诉我。

I have created my custom adorner to cover my main window with a gray canvas alongwith a textblock at center to show some status text while i was working on other window.

What i am currently doing is fetching the required adornerElement(ie Canvas with a textblock) from my resources and passing it to an adorner in my view constructor like this -

 ResourceDictionary reportResourceDictionary = App.LoadComponent(new Uri("Resources/ReportResources.xaml", UriKind.Relative)) as ResourceDictionary;
 UIElement adornerElement = reportResourceDictionary["RefreshingReportAdorner"] as UIElement;
 mainWindowBlockMessageAdorner = new MainWindowBlockMessageAdorner(mainPanel, adornerElement);

But i want to update that text in textblock in some scenarios say if i click on some button in other window but how to update the text dynamically??

Adorner element from Resource file-

<Grid x:Key="RefreshingReportAdorner">
        <Rectangle Fill="Gray"
                   StrokeThickness="1"
                   Stroke="Gray"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Stretch"/>
        <Border BorderBrush="Black"
                BorderThickness="2"
                Background="White"
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
            <TextBlock i18n:LanguageManager.VisualId="6"
                       Text="Some Text(Update dynamically)"                       
                       Padding="15,10,15,10"/>
        </Border>
    </Grid>

Let me know if additional code or approach required..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2024-11-09 13:58:32

您是否尝试过创建一些模型并将其推送到 RefreshingReportAdorner 元素的 DataContext?

代码:

 var reportResourceDictionary = App.LoadComponent(new Uri("Resources/ReportResources.xaml", UriKind.Relative)) as ResourceDictionary;
 var adornerElement = reportResourceDictionary["RefreshingReportAdorner"] as FrameworkElement;
 var model = new Model(); 
 model.MyText = "Initial text";
 adornerElement.DataContext = model;
 mainWindowBlockMessageAdorner = new MainWindowBlockMessageAdorner(mainPanel, adornerElement);
 ... 
 model.MyText = "Text after click";

XAML:

        <TextBlock i18n:LanguageManager.VisualId="6"
                   Text="{Binding MyText}"                       
                   Padding="15,10,15,10"/>

型号:

public class Item : INotifyPropertyChanged
{
    private string _myText;
    public string MyText
    {
        get
        {
            return this._myText;
        }
        set
        {
            this._myText= value;
            this.OnPropertyChanged("MyText");
        }
    }
}

Have you tried to create some model and push it to RefreshingReportAdorner element's DataContext?

Code:

 var reportResourceDictionary = App.LoadComponent(new Uri("Resources/ReportResources.xaml", UriKind.Relative)) as ResourceDictionary;
 var adornerElement = reportResourceDictionary["RefreshingReportAdorner"] as FrameworkElement;
 var model = new Model(); 
 model.MyText = "Initial text";
 adornerElement.DataContext = model;
 mainWindowBlockMessageAdorner = new MainWindowBlockMessageAdorner(mainPanel, adornerElement);
 ... 
 model.MyText = "Text after click";

XAML:

        <TextBlock i18n:LanguageManager.VisualId="6"
                   Text="{Binding MyText}"                       
                   Padding="15,10,15,10"/>

Model:

public class Item : INotifyPropertyChanged
{
    private string _myText;
    public string MyText
    {
        get
        {
            return this._myText;
        }
        set
        {
            this._myText= value;
            this.OnPropertyChanged("MyText");
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文