Ionut
Ionut

Reputation: 1749

Define DesignWidth with a constant in a XAML file

I would like to define the DesignWidth value with a constant but the view it does not seem to have the defined width in Blend. I have a Constants.class

public static class Constants
{
    public static int ApplicationWidth { get { return 1280;} }
    public static int ApplicationHeight { get { return 720; } }
}

and the View.xaml

<UserControl
    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"
    xmlns:constants="clr-namespace:app.Constants"
    d:DesignWidth="{x:Static constants:Constants.ApplicationWidth}">
</UserControl>

In Visual Studio the View Width is 267px and in Blend is 262px. How can I set the Width without hard coding the values in the XAML files in order to have the desired size in Blend an Visual Studio ?

Upvotes: 0

Views: 1198

Answers (1)

Maximus
Maximus

Reputation: 3448

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:constants="clr-namespace:app.Constants"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d"
  d:DesignWidth="{Binding Source={x:Static constants:Constants.ApplicationWidth}}">

Upvotes: 1

Related Questions