/ / WPFデータバインディングがViewModelの列幅を変更する - wpf、binding

WPFデータバインディングはViewModelの列幅を変更します - wpf、バインディング

3列の単純なグリッドがあります。

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding NavigationWidth}"  />
<ColumnDefinition Width="4" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
</Grid>

<GridSplitter Grid.Column="1" Grid.Row="2"
ResizeDirection="Columns"
Background="Silver"
Width="2" HorizontalAlignment="Center"
VerticalAlignment="Stretch" />

<ContentControl x:Name="navigationView"  Grid.Column="0" Grid.Row="1"/>
<ContentControl x:Name="workspaceView" Grid.Column="2" Grid.Row="1"  />


// The NavigationWidth is belongs to the ViewModel

public int NavigationWidth
{
get{ return _navigationWidth; }
set{
_navigationWidth = value;
OnPropertyChanged("NavigationWidth");
}
}

そのため、上記の設定に基づいて、ユーザーがナビゲートする場所に応じて、コードはグリッドの最初の列の幅を設定しようとします。 ユーザーが手動で幅を変更しなければ、すべてうまくいきます。

ユーザーが設定した幅をコードが上書きする可能性はありますか

ありがとう、

オースティン

回答:

回答№1は0

ユーザーが設定した幅をコードが上書きする可能性はありますか。

バインディングが次のような2つの方法である限り、目的の時間/場所に値NavigationWidthを設定することで可能です。

<ColumnDefinition Width="{Binding NavigationWidth, Mode=TwoWay}