是的,我已经用Google搜索了这个废话..我似乎无法找到任何人试图保存用户编辑的位置(如在工具栏中重新定位工具栏)的布局他们的工具栏..这要么是如此简单我是一个白痴,还是很难......我甚至无法找到一个起点,比如我想要保存和加载的属性是什么?当然不是x,y,宽度和高度?这只是我应该考虑获得第三方工具吗?
基本上我想要做的是在用户在工具栏托盘中移动工具栏后保存工具栏的位置。
我的Xaml看起来像这样:
<src:BaseWindow x:Class="RPDM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"
xmlns:src="clr-namespace:RPDM"
Title="MainWindow" Height="600" Width="800" Loaded="OnLoaded">
<src:BaseWindow.Resources>
<DockPanel x:Name="dockMain">
<ToolBarTray DockPanel.Dock="Top" x:Name="tbMain">
<ToolBar Visibility="{Binding Path=ShowToolBarFile, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}}">
<Button Click="mnuFileNewProject_Click" ToolTip="New Dataflow Project">
<Image Source="{StaticResource imgNewDataFlow_24}" Width="24" Height="24"/>
</Button>
<Button Click="mnuFileNewAutomation_Click" ToolTip="New Automation Project">
<Image Source="{StaticResource imgNewAutomation_24}" Width="24" Height="24"/>
</Button>
<Button Click="mnuFileOpen_Click" ToolTip="Open">
<Image Source="{StaticResource imgOpen_24}" Width="24" Height="24"/>
</Button>
<Button Click="mnuFileSave_Click" ToolTip="Save">
<Image Source="{StaticResource imgSave_24}" Width="24" Height="24"/>
</Button>
</ToolBar>
<ToolBar Visibility="{Binding Path=ShowToolBarLayout, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}}">
<Button Click="mnuLayoutZoomIn_Click" ToolTip="Zoom In">
<Image Source="{StaticResource imgZoomIn_24}" Width="24" Height="24"/>
</Button>
<Button Click="mnuLayoutZoomOut_Click" ToolTip="Zoom Out">
<Image Source="{StaticResource imgZoomOut_24}" Width="24" Height="24"/>
</Button>
<Button Click="mnuLayoutZoomToFit_Click" ToolTip="Zoom to Fit">
<Image Source="{StaticResource imgFitToView_24}" Width="24" Height="24"/>
</Button>
<Button Click="btnToggleOrientation_Click" ToolTip="Toggle Orientation">
<Image Source="{StaticResource imgOrientation_24}" Width="24" Height="24"/>
</Button>
</ToolBar>
</ToolBarTray>
</DockPanel>
答案 0 :(得分:2)
使用XamlWriter.Save方法序列化逻辑树的根元素,然后在XamlReader.Load方法的帮助下重新加载它。
我认为这对你有用。有关更多参考,请访问此msdn主题: