Access window size in xaml or data model
When resizing the window we have to do something like
Is it possible for a xaml or a data model to access these values?
Tried something like as found on StackOverflow but that's probably just WPF like.
Storing the pointer to the data model somewhere global works but doesn't feel elegant.
Code: Select all
m_view->SetSize( this->width(), this->height() );
Tried something like
Code: Select all
"{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}"
Storing the pointer to the data model somewhere global works but doesn't feel elegant.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Access window size in xaml or data model
Xaml root element fills by default the avaliable space specified in view->SetSize(), so you can bind to root ActualWidth and ActualHeight if you need that info from the xaml:
Could that work for you?
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Root">
...
<Rectangle
Width="{Binding ActualWidth, ElementName=Root}"
Height="{Binding ActualHeight, ElementName=Root}" .../>
...
</Grid>
Re: Access window size in xaml or data model
That works, thanks. The reason I want this is that I have
just below the root element. So when these values are set smaller than the actual window size it can be use to scale the entire gui.
So I solved that now by feeding the window size into the view model, multiply it with the scaling factor and supply the binding.
Now that I see that it is possible to get from the xaml I need to find out how to multiply that with the scaling factor.
Code: Select all
<Viewbox>
<Grid x:Name="GameGrid" Width="{Binding WindowWidth}" Height="{Binding WindowHeight}">
...
So I solved that now by feeding the window size into the view model, multiply it with the scaling factor and supply the binding.
Now that I see that it is possible to get from the xaml I need to find out how to multiply that with the scaling factor.
Re: Access window size in xaml or data model
You can use converters for this although I think that the idea of doing the maths in code-behind and exposing them in the data context is not necessarily bad.Now that I see that it is possible to get from the xaml I need to find out how to multiply that with the scaling factor.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests