Window
のいくつかのプロパティをxmlに保存して終了し、再起動して起動時に適用したいです。ConfigからLocationとWindowSizeを適用できません
XML
に値を保存していますが、これまでのところうまくいきました。 私のViewModelの値を関連するChangedEvents
に更新します。
[Serializable]
public class UserSettings
{
public double WindowWidth { get; set; }
public double WindowHeight { get; set; }
//GridSplitter
public double GridLength_Pixels { get; set; }
public double WindowPositionX { get; set; }
public double WindowPositionY { get; set; }
}
この
は私XAML
です:
<Window x:Class="MonitorTool.Windows.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MonitorTool"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
Title="Transport Monitor"
MinWidth="300"
MinHeight="550"
Height="{Binding WindowHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Width="{Binding WindowWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Topmost="{Binding ElementName=TopMostCheckBox, Path=IsChecked}"
Icon="{Binding Path=Icon, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Left="{Binding Path=LocationX, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Top="{Binding Path=LocationY, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
[...]
propertiesin私のViewModelにあるすべて全く同じだから、僕はここに1をもたらすだろうが、それは明らかである:だから
public double WindowWidth
{
get { return _windowWidth; }
set
{
_windowWidth = value;
OnPropertyChanged("WindowWidth");
}
}
私はApplyUserSettings
というメソッドを作成しました。これはMainWindow_ContentRendered
で呼び出され、ここでConfigをロードし、これらの値をプロパティに入力します。
しかし、何も起こっていないし、どこで解決策を探すべきか分からない。 私は、pplがdefaultSettingsに格納されているが、それは大きな違いのようには見えないので、多くの例題をオンラインで見つけました。それで、自分の設定ファイルでも同じように動作するはずです。
ここで何が間違っているのでしょうか?
EDIT:
それはMinWidth
とMinHeight
とウィンドウのスタートアップのように思えます。
EDITのV2:ViewModelに:
MainWindow.xaml.cs
で:
public MainWindow()
{
InitializeComponent();
if(MainWindowViewmodel.Instance == null)
{
MainWindowViewmodel.Instance = new MainWindowViewmodel(this);
}
DataContext = MainWindowViewmodel.Instance;
InitializeTray();
TrayIcon.Visible = true;
}
あなたは値が正しく設定されて見ることができますが、それは適用されませんそのように思えるとして;(
より小さい値に設定することができませんか? XAMLで作成していますか?私。あなたのウィンドウがxamlで起動するたびに新しいモデルが作成されますか? –
@GingerNinjaいいえ私はインスタンスを持っています私は同じVMを使用するスプラッシュスクリーンを持っていますが、そこでは同じインスタンスを使用します –
StackOverflowには同じコンテキストと多くの理由で何十もの質問があります。幅が機能していません。彼らはまた、多くの回避策を提案しています。あなたは見たことがありますかこれらのいずれかを試しましたか?もしこれがうまくいかないのであれば? – Athafoud