首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在TextBox中切换FlipView中的FlipView

在TextBox中切换FlipView中的FlipView
EN

Stack Overflow用户
提问于 2013-07-30 23:47:29
回答 1查看 239关注 0票数 0

我有一个FlipView,其中每个FlipViewItem都包含一个绑定到ObservableCollection的TextBox,我需要为FlipView中的文本框切换TextWrapping。

到目前为止,我已经尝试了我所能想到的一切,但在网上没有任何帮助。我找不到任何结果。

我该怎么做?

XAML:

..。

代码语言:javascript
复制
// This part is for the AppBar Toggle button
<ToggleButton x:Name="wordWrapToggleButton" Style="{StaticResource WordWrapAppBarButtonStyle}" />

..。

代码语言:javascript
复制
// For the FlipView
<FlipView x:Name="flipView" Grid.Row="1" Margin="0, 50, 0, 0" ItemsSource="{Binding Note, Mode=TwoWay}" Loaded="flipView_Loaded" SelectionChanged="flipView_SelectionChanged" FontSize="12.667">
    <FlipView.ItemTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Contents, Mode=TwoWay}" Tag="{Binding Title, Mode=TwoWay}" TextWrapping="{Binding ElementName=wordWrapToggleButton, Path=.CheckState, Mode=TwoWay}" IsSpellCheckEnabled="True" AcceptsReturn="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="{x:Null}" FontSize="{Binding ElementName=flipView, Path=FontSize, Mode=OneWay}" />
        </DataTemplate>
    </FlipView.ItemTemplate>
</FlipView>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-31 05:47:50

您必须创建一个绑定转换器,将bool转换为TextWrapping

代码语言:javascript
复制
public class BooleanToTextWrappingConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        return (value is bool && (bool)value) ? TextWrapping.Wrap : TextWrapping.NoWrap;
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        return value is TextWrapping && (TextWrapping)value == TextWrapping.Wrap;
    }
}

并在你的装订中使用

代码语言:javascript
复制
<Page.Resources>
    <local:BooleanToTextWrappingConverter x:Key="BooleanToTextWrappingConverter"/>
</Page.Resources>
...
<DataTemplate>
    <TextBox Text="{Binding Contents, Mode=TwoWay}"
        TextWrapping="{Binding Path=IsChecked, ElementName=wordWrapToggleButton,
                       Converter={StaticResource BooleanToTextWrappingConverter}}"/>
</DataTemplate>

请注意,TextWrapping绑定不是双向的,因为这是没有意义的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17959355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档