Hi,@Santhosh Badam .My previous solution was based on calculator effects. The calculator does not seem to include repositioning.
But window size changes or minimize then maximize the contents are not Wrapping.
For text wrapping, you can set the property TextWrapping="Wrap" for the TextBlock.
<TextBlock Grid.Row="2" TextWrapping="Wrap" Text="Forgot your password?..................................." Width="{Binding ElementName=MainPanel, Path=ActualWidth, Converter={StaticResource WidthConverter}}" HorizontalAlignment="Center" Margin="0,10,0,0"/>
For more information on layouts in WPF, see Document Panel Elements and Customizing Layout Behavior.
But my requirement is as like the below link suggests Reposition, Resize, Reflow, and Show/Hide. Based on the content should perform in "WPF app".
Reposition:
<Window.Resources>
<local:WidthToOrientationConverter x:Key="WidthToOrientationConverter"/>
<Style TargetType="StackPanel">
<Setter Property="Orientation" Value="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Converter={StaticResource WidthToOrientationConverter}}"/>
</Style>
</Window.Resources>
<StackPanel >
<TextBlock Text="Hello, World wwwwwwwwwwwwwwww!" Background="AliceBlue" TextWrapping="Wrap" FontSize="24"/>
<TextBlock Text="Hello, World wwwwwwwwwwwwwwwwwww!" Background="Pink" TextWrapping="Wrap" FontSize="24"/>
</StackPanel>
WidthToOrientationConverter :
public class WidthToOrientationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double width)
{
return width > 400 ? Orientation.Horizontal : Orientation.Vertical;
}
return Orientation.Vertical;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Resize:
<Window x:Class="LayoutDemo.MainWindow"
...
xmlns:local="clr-namespace:LayoutDemo"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:MainViewModel />
</Window.DataContext>
<Window.Resources>
<local:WidthConverter x:Key="WidthConverter"/>
</Window.Resources>
<DockPanel>
<Canvas Width="{Binding RelativeSource={RelativeSource AncestorType=DockPanel}, Path=ActualWidth, Converter={StaticResource WidthConverter}}">
<TextBlock Text="Hello, World wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww!"
Width="{Binding RelativeSource={RelativeSource AncestorType=DockPanel}, Path=ActualWidth, Converter={StaticResource WidthConverter}}" TextWrapping="Wrap"
FontSize="24"/>
</Canvas>
</DockPanel>
</Window>
public class WidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double width)
{
return width * 0.9; // Adjust as needed for your layout
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}