使用折叠在Windows应用商店应用项目中折叠TextBlock [英] Using Collapse to Collapse a TextBlock in Windows Store App project

查看:90
本文介绍了使用折叠在Windows应用商店应用项目中折叠TextBlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有文字,我需要让TextBlock崩溃,并且在WPF中有很多这样的例子(例如下面的那个)。如果我将触发器代码放在我的Windows Store App项目中,则编译告诉我"未知成员"触发'元素'样式'上的

I need for my TextBlock to collapse if there's no text, and there's many examples of doing this on the web in WPF (such as the one below). If I put the trigger code below in my Windows Store App project, the compile tells me "Unknown member 'Triggers' on element 'Style'.

如果我尝试将我的TextBlock Visibility属性设置为Windows.UI.Xaml.Visibility.Collapsed在代码隐藏中,它没有任何效果,并且空TextBlock继续可见。您可以在下面的第二个代码示例
中看到我如何使用TextBlock设置Grid。

If I try to set my TextBlock Visibility property to Windows.UI.Xaml.Visibility.Collapsed in the code-behind, it has no effect, and the empty TextBlock continues to be visible. You can see how I've set up a Grid with a TextBlock in the second code sample below.

任何想法?我真的需要TextBlock在它为空时消失。

Any ideas? I really need for the TextBlock to disappear when it is empty.

谢谢...

<Style x:Key="CollapsableTextblock" TargetType="TextBlock"> 
    <Style.Triggers> 
        <Trigger Property="Text" Value=""> 
            <Setter Property="Visibility" Value="Collapsed"/> 
        </Trigger> 
    </Style.Triggers> 
</Style> 
<TextBlock Text="" Style="{DynamicResource CollapsableTextblock}" />





<Grid x:Name="gridMain">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*"/>
        <ColumnDefinition Width="3*"/>
    </Grid.ColumnDefinitions>

    <TextBlock x:Name="txtReport"/>
    <local:MapBing Grid.Column="1" />
</Grid>

Randy

推荐答案

错误是正确的。您不能在Windows应用商店应用中使用WPF特定代码。您可以查看文档或使用Visual Studio中的对象浏览器来查看可用于解决方案的类和方法。

The error is correct. You cannot use WPF specific code in Windows Store apps. You can check the documentation or use the Object Browser in Visual Studio to see what classes and methods are available for your solution.

以编程方式设置TextBlock对Collapsed的可见性应该可以正常工作我的考试。 TextBlock没有TextChanged事件,因此您无法直接进入该事件。您应该能够将块的可见性绑定到基础
文本源。

Setting the TextBlock's visibility to Collapsed programmatically should work just fine and does in my test. The TextBlock doesn't have a TextChanged event so you cannot tap into that directly. You should be able to bind the block's Visibility to the underlying text source.

- Rob


这篇关于使用折叠在Windows应用商店应用项目中折叠TextBlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆