Hi, I'm trying to implement a certain "Resize" behaviour, but despite several attempts I've failed to do so.
Please Help !!!!
Here's the code:
<DataTemplate DataType="{x:Type models:MeasBoxModel}">
<!--<Canvas Name="MeasBoxFigureCanvas">-->
<DockPanel>
<TextBlock
Background="Blue"
HorizontalAlignment="Center"
DockPanel.Dock="Top"
Visibility="{Binding IsVisible,Converter={StaticResource VisibilityOfBool}}">
<TextBlock.Text>
<MultiBinding StringFormat="Diag: {0:F2} dX: {1:F} dY: {2:F2}">
<Binding Path="Diag" />
<Binding Path="Delta.X" />
<Binding Path="Delta.Y" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock
Background="Blue"
HorizontalAlignment="Center"
DockPanel.Dock="Bottom"
Visibility="{Binding IsSelected,Converter={StaticResource VisibilityOfBool}}">
<TextBlock.Text>
<MultiBinding StringFormat=" Center: [{0:F2} , {1:F2}]">
<Binding Path="Center.X" />
<Binding Path="Center.Y" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<views:MeasBoxFigureUc Canvas.Left="{Binding Left, Mode=TwoWay}"
Canvas.Top="{Binding Top, Mode=TwoWay}"
IsResizable="{Binding IsResizable, Mode=TwoWay}"
Width="{Binding Width, Mode=TwoWay}"
Height="{Binding Height, Mode=TwoWay}"
FigureGroupProperty="{Binding figureGroupProperty}"
Visibility="{Binding IsVisible, Mode=TwoWay, Converter={StaticResource VisibilityOfBool}}"/>
</DockPanel>
</DataTemplate>
Suspected Problem Description:
The problem is that when I try to resize the MeasBoxFigure (using the Thumb class), what happens is:
•When the upper label is wider than the box, after every width modification the box is centered relatively to the upper lablel.
•When the box is wider than the upper label, the resize behavior is as expected, only the position of the dragged size is changed, and the opposite side is fixed.
I think that because both the TextBlocks and the box are in the same DockPanel, somehow the properties of the DockPanel are integrated in the box, and when I try to change the box’s width (as shown in the OnDragDelta(…) method below) it affects the whole stack panel and automates the layout.
If I change the alignment of the box to left, the resize works as expected, but that’s a problem because I want the labels to be centers relative to the box.
I need some way the hold all the 3 elements together (2 TextBlocks and the box figure) and when I change the size of the box, the labels need to Center relative to it automatically).
Please Help !!!!
Here's the code:
<DataTemplate DataType="{x:Type models:MeasBoxModel}">
<!--<Canvas Name="MeasBoxFigureCanvas">-->
<DockPanel>
<TextBlock
Background="Blue"
HorizontalAlignment="Center"
DockPanel.Dock="Top"
Visibility="{Binding IsVisible,Converter={StaticResource VisibilityOfBool}}">
<TextBlock.Text>
<MultiBinding StringFormat="Diag: {0:F2} dX: {1:F} dY: {2:F2}">
<Binding Path="Diag" />
<Binding Path="Delta.X" />
<Binding Path="Delta.Y" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock
Background="Blue"
HorizontalAlignment="Center"
DockPanel.Dock="Bottom"
Visibility="{Binding IsSelected,Converter={StaticResource VisibilityOfBool}}">
<TextBlock.Text>
<MultiBinding StringFormat=" Center: [{0:F2} , {1:F2}]">
<Binding Path="Center.X" />
<Binding Path="Center.Y" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<views:MeasBoxFigureUc Canvas.Left="{Binding Left, Mode=TwoWay}"
Canvas.Top="{Binding Top, Mode=TwoWay}"
IsResizable="{Binding IsResizable, Mode=TwoWay}"
Width="{Binding Width, Mode=TwoWay}"
Height="{Binding Height, Mode=TwoWay}"
FigureGroupProperty="{Binding figureGroupProperty}"
Visibility="{Binding IsVisible, Mode=TwoWay, Converter={StaticResource VisibilityOfBool}}"/>
</DockPanel>
</DataTemplate>
Suspected Problem Description:
The problem is that when I try to resize the MeasBoxFigure (using the Thumb class), what happens is:
•When the upper label is wider than the box, after every width modification the box is centered relatively to the upper lablel.
•When the box is wider than the upper label, the resize behavior is as expected, only the position of the dragged size is changed, and the opposite side is fixed.
I think that because both the TextBlocks and the box are in the same DockPanel, somehow the properties of the DockPanel are integrated in the box, and when I try to change the box’s width (as shown in the OnDragDelta(…) method below) it affects the whole stack panel and automates the layout.
If I change the alignment of the box to left, the resize works as expected, but that’s a problem because I want the labels to be centers relative to the box.
I need some way the hold all the 3 elements together (2 TextBlocks and the box figure) and when I change the size of the box, the labels need to Center relative to it automatically).