Click here to Skip to main content
15,886,873 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Can I put Polygon inside Button Template Dynamically? Pin
Abhinav S19-May-09 3:56
Abhinav S19-May-09 3:56 
GeneralRe: Can I put Polygon inside Button Template Dynamically? Pin
salon19-May-09 23:35
salon19-May-09 23:35 
GeneralRe: Can I put Polygon inside Button Template Dynamically? Pin
Abhinav S20-May-09 4:55
Abhinav S20-May-09 4:55 
QuestionRegarding treeview using MVVM pattern Pin
Ravi Mori18-May-09 21:42
Ravi Mori18-May-09 21:42 
AnswerRe: Regarding treeview using MVVM pattern Pin
Pete O'Hanlon19-May-09 0:15
mvePete O'Hanlon19-May-09 0:15 
AnswerRe: Regarding treeview using MVVM pattern Pin
Mike Fuchs8-Jul-10 22:38
Mike Fuchs8-Jul-10 22:38 
GeneralRe: Regarding treeview using MVVM pattern Pin
Robert Graves6-Sep-11 9:02
Robert Graves6-Sep-11 9:02 
QuestionUserControl does not assume height of parent container Pin
ausadmin18-May-09 19:47
ausadmin18-May-09 19:47 
I have been struggling with this issue for some time, and I have now constructed a simple example to demonstate the problem. I am not sure whether this is an issue with WPF or my lack of understanding.

As part of our application, I have created a wizard along the lines of Creating an Internationalized Wizard in WPF. This uses the MVVM pattern and the various pages of the wizard are implemented in User Controls.

The problem that I have is when the wizard window is resized, the UserControl does not take the height of the window. However it does take the width of the window. The result is that controls such as a list box, which the user may need to have resize with the window, do not resize.

I have removed the complexity of our app, and created a very simple example with a window, that just contains a HeaderedContentControl, which contains the model for the UserControl.

The window is
<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:UserControlDemo"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <DataTemplate DataType="{x:Type local:SimpleUserControlModel}">
            <local:SimpleUserControl />
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <HeaderedContentControl Name="hcControl"  Margin="20" Content="{x:Type local:SimpleUserControl}" 
                                    Height="auto" Width="auto" VerticalContentAlignment="Stretch"  />
    </Grid>
</Window>


Window code:
Class Window1 
    Private _simpleModel As SimpleUserControlModel

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        _simpleModel = New SimpleUserControlModel
        hcControl.Content = _simpleModel
    End Sub
End Class


User control:
<UserControl x:Class="SimpleUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid>
            <Border Margin="5" BorderThickness="5" BorderBrush="Red" />
    </Grid>
</UserControl>


User control model:
Public Class SimpleUserControlModel
End Class


The UserControl just contains a red border, which makes it easy to see its size. If you run the application and drag the corner of window1, the width of the red border changes, but its height remains at 0. Checking the height (in fact it is the ActualHeight property) of the HeaderedContentControl, it is set as expected (about 260) - I had expected the UserControl would inherit the value of this property, so its height would be set automatically.

It would be greatly appreciated if someone could explain what I am missing here...

Please note that a workaround is relatively easy and has been implemented in our app: add a property for the required height to SimpleUserControlModel then bind the UserControl height to the property. Then by catching the Window's SizeChanged event, the property can be updated (its not quite that simple, because you also need a timer to add a delay to avoid handling every window SizeChanged event).

Thanks for any help.
Tim
AnswerRe: UserControl does not assume height of parent container [modified] Pin
Mark Salsbery19-May-09 6:41
Mark Salsbery19-May-09 6:41 
GeneralRe: UserControl does not assume height of parent container Pin
ausadmin19-May-09 11:05
ausadmin19-May-09 11:05 
GeneralRe: UserControl does not assume height of parent container Pin
Mark Salsbery19-May-09 11:14
Mark Salsbery19-May-09 11:14 
GeneralRe: UserControl does not assume height of parent container Pin
mick codeproject19-Jan-10 23:10
mick codeproject19-Jan-10 23:10 
QuestionHelp with positioning text pointer in TextBox after formatting. Pin
Member 232448318-May-09 10:47
Member 232448318-May-09 10:47 
AnswerRe: Help with positioning text pointer in TextBox after formatting. Pin
Mark Salsbery18-May-09 13:49
Mark Salsbery18-May-09 13:49 
GeneralRe: Help with positioning text pointer in TextBox after formatting. Pin
Member 232448318-May-09 14:01
Member 232448318-May-09 14:01 
QuestionSilverlight newbie Pin
Xandip18-May-09 3:37
Xandip18-May-09 3:37 
AnswerRe: Silverlight newbie Pin
Pete O'Hanlon18-May-09 4:13
mvePete O'Hanlon18-May-09 4:13 
AnswerRe: Silverlight newbie Pin
Kevin McFarlane19-May-09 5:45
Kevin McFarlane19-May-09 5:45 
GeneralRe: Silverlight newbie Pin
Xandip19-May-09 19:37
Xandip19-May-09 19:37 
Questionmulti Master-Detail view Pin
daniel radford18-May-09 2:42
daniel radford18-May-09 2:42 
AnswerRe: multi Master-Detail view Pin
Mark Salsbery18-May-09 5:40
Mark Salsbery18-May-09 5:40 
GeneralRe: multi Master-Detail view Pin
daniel radford19-May-09 6:39
daniel radford19-May-09 6:39 
GeneralRe: multi Master-Detail view Pin
Mark Salsbery19-May-09 6:57
Mark Salsbery19-May-09 6:57 
GeneralRe: multi Master-Detail view Pin
daniel radford20-May-09 0:47
daniel radford20-May-09 0:47 
QuestionHelp Require: Huge DataBinding makes the Application Hang!!! Pin
Kunal Chowdhury «IN»17-May-09 20:57
professionalKunal Chowdhury «IN»17-May-09 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.