0

Settings.settingsユーザーが画像を選択して保存すると、すべてのボタン、ナビゲーションバーの項目などに適用される WPF アプリケーションを作成しました。ファイルに画像パスを保存するコードを書きました。画像を選択すると、これがデータベースに保存されますがnavigation bar items or buttons source of image、アプリケーションを再起動するまで適用されません。ここに私のコードは次のとおりです。

    public partial class MainWindow : DXWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            Refreshicon();
        }

        public void Refreshicon()
        {
            BitmapImage bi = new BitmapImage(new Uri(ApplicationSettings.Default.ImageName));  //Image From Settings File!
            MessageBox.Show("Image Path" + bi.ToString());
            navBarGroup1.ImageSource = bi;
            navBarGroup2.ImageSource = bi;
            navBarItem1.ImageSource = bi;
            navBarItem2.ImageSource = bi;
        }

アプリケーションを再起動せずにユーザー定義のイメージ パスを適用するにはどうすればよいnavigation bar items or buttonsですか?

編集 //以下のコードは、画像を保存してRefreshicon()関数を呼び出すためのものです

 private void Button_Click_SaveImage(object sender, RoutedEventArgs e)
        {
        string imagepath = ApplicationSettings.Default.ImageName;
        ApplicationSettings.Default.SetImage(imageEdit1.ImagePath);
        MainWindow a = null;
        if (a == null)
            {
            a=new MainWindow();
            a.Refreshicon();

            }

        }
4

1 に答える 1

2

画像パスをファイルRefreshicon()に書き込んでいるコードが何であれ、メソッドを呼び出す必要があります。Settings.settings

編集:

Button_Click_SaveImageが 以外のウィンドウにある場合は、元のインスタンスへの参照を子ウィンドウ クラスMainWindowに追加し、そのメソッドを呼び出す必要があります。このようなもの:MainWindowRefreshicon()

子ウィンドウ クラスでは、それを DialogWindow と呼びましょう。

public class DialogWindow : Window {
    // All your code here . . .

    public MainWindow Parent { get; set; }

    private void Button_Click_SaveImage( object sender, RoutedEventArgs e ) {
        // Your code up to the MainWindow a line goes here
        Parent.Refreshicon();
    }
}

次に、 でMainWindow、表示用に子ウィンドウをインスタンス化するときに、次のようにします。

DialogWindow childWindow = new DialogWindow();
childWindow.Parent = this;
于 2013-09-06T17:49:08.767 に答える