将文本设置为自定义标题页枢轴

编程入门 行业动态 更新时间:2024-10-28 11:33:19
本文介绍了将文本设置为自定义标题页枢轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我已经创建了数据透视页面,我希望在顶部的 2 个文本块中显示一些信息.我已经创建了 DataTemplate 并为文本字段设置了 x:names.但是我无法从页面构造函数寻址到此文本块并将文本放在那里.为什么?我怎么能欺骗这种情况?我需要在页面加载时将信息放入文本块.

I've created pivot page and I wish to display in the 2 text blocks at the top some information. I've created DataTemplate and set x:names for text fields. But I can't adress from page constructor to this text blocks and put there text. Why? And how can I cheat this situation? I need to put to text blocks information while page are loading.

        <controls:Pivot.TitleTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock x:Name="textBlock_eventID" TextWrapping="NoWrap" Margin="0"/>
                    <TextBlock x:Name="textBlock_eventName"  TextWrapping="NoWrap" Opacity="0.7"/>
                </StackPanel>
            </DataTemplate>
        </controls:Pivot.TitleTemplate>

推荐答案

使用 DataTemplate 的目的是定义业务对象的表示.也就是说,如果你有一个像下面这样的类:

The point of using a DataTemplate is to define the presentation of a business object. That is to say that if you have a class like the following:

public class MyClass
{
    public string StringOne { get; set; }
    public string StringTwo { get; set; }
}

如果您将 Pivot 控件的 Title 属性设置为此类的一个实例,则可以使用 DataTemplate 来定义您希望它的外观.

If you set the Title property of your Pivot control to an instance of this class, a DataTemplate can be used to define what you want it to look like.

在您的情况下,模板可能如下所示:

In your case, the template could look like this:

    <controls:Pivot.TitleTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding StringOne}" TextWrapping="NoWrap" Margin="0"/>
                <TextBlock Text="{Binding StringTwo}" TextWrapping="NoWrap" Opacity="0.7"/>
            </StackPanel>
        </DataTemplate>
    </controls:Pivot.TitleTemplate>

然后从代码隐藏中,您将设置 Pivot 控件的 Title 属性.像这样:

Then from the code-behind, you would set the Title property of the Pivot control. Something like this:

 myPivotControl.Title = new MyClass 
     { 
         StringOne = "Some String", 
         StringTwo = "Some other string" 
     };

<小时>

还有另一种方法可以做到这一点,它允许您从后面的代码中简单地设置文本框,但这不涉及 DataTemplate.


There is another way you could do this, which would allow you to simply set the text boxes from the code behind, but this does not involve a DataTemplate.

像下面这样设置 Pivot 控件的 Title 属性,将使您能够按名称访问 TextBox:

Setting the Title property of your Pivot control like the following, will enable you to access the TextBox's by name:

    <controls:Pivot.Title>
        <StackPanel Orientation="Horizontal">
            <TextBlock x:Name="textBlock_eventID" TextWrapping="NoWrap" Margin="0"/>
            <TextBlock x:Name="textBlock_eventName"  TextWrapping="NoWrap" Opacity="0.7"/>
        </StackPanel>
    </controls:Pivot.Title>

阅读这篇文章,了解有关 DataTemplates 的更多信息

这篇关于将文本设置为自定义标题页枢轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 14:19:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117467.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:枢轴   自定义   设置为   文本   标题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!