LoginSignup
1
1

More than 5 years have passed since last update.

[Silverlight] TextをWrapする方法

Posted at

MaxWidthかWidthが設定されていないとどこでWrapしていいかわからないようです。
そのため、自分の親要素のActualWidthをMaxWidthにバインドすることで解決できそう。

MainView.xaml
<UserControl x:Class="SilverlightApplication3.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"></ColumnDefinition>
            <ColumnDefinition Width="auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Column="0">
            <Button Content="Resize" Click="Button_Click"></Button>
        </StackPanel>
        <StackPanel x:Name="Parent" Grid.Column="1" Width="300">
            <TextBlock
                x:Name="tb"
                TextWrapping="Wrap"
                MaxWidth="{Binding ElementName=*Parent*, Path=ActualWidth}"
                Text="テスト22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"></TextBlock>
        </StackPanel>
    </Grid>
</UserControl>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1