При максимизации экрана в wpf связанная ширина срабатывает дважды. Как это исправить - PullRequest
0 голосов
/ 16 мая 2018

Когда я максимизирую окно приложения wpf, ширина привязки обновляется дважды. Первый с правильной шириной, а второй с предыдущей шириной.

Это код, который я использую. (Я пытался поместить его в отдельный проект)

XAML

<catel:Window x:Class="WPFTestApplication1.Views.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:catel="http://schemas.catelproject.com"
          ResizeMode="CanResize" Width="{Binding W,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Height="{Binding H,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
          MinHeight="400" MinWidth="600">

     <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Label Grid.Row="0" Grid.Column="0" Content="{Binding Title}" />
        <Label Grid.Row="1" Grid.Column="0" Content="Here goes your real content" />
    </Grid>

</catel:Window>

MainWindowViewModel:

public class MainWindowViewModel : ViewModelBase
{
    public MainWindowViewModel()
    {
    }

    public override string Title { get { return "WPFTestApplication1"; } }

    // TODO: Register models with the vmpropmodel codesnippet
    // TODO: Register view model properties with the vmprop or vmpropviewmodeltomodel codesnippets
    // TODO: Register commands with the vmcommand or vmcommandwithcanexecute codesnippets

    protected override async Task InitializeAsync()
    {
        await base.InitializeAsync();

        // TODO: subscribe to events here
    }

    protected override async Task CloseAsync()
    {
        // TODO: unsubscribe from events here

        await base.CloseAsync();
    }


    public double H
    {
        get { return GetValue<double>(HProperty); }
        set { SetValue(HProperty, value); Console.WriteLine(value); }
    }

    public static readonly PropertyData HProperty = RegisterProperty(nameof(H), typeof(double), null);


    public double W
    {
        get { return GetValue<double>(WProperty); }
        set { SetValue(WProperty, value); Console.WriteLine(value); }
    }

    public static readonly PropertyData WProperty = RegisterProperty(nameof(W), typeof(double), null);
}

Мне нужны значения для масштабирования чего-либо в окне, и оно заканчивается неправильным значением. Как мне это исправить?

...