[英]C# WPF AvalonDock loses data binding after reloading layout
I'm working with avalon-dock plugin and found a super annoying problem.我正在使用 avalon-dock 插件,发现一个非常烦人的问题。 My application uses data-binding in xamls.
我的应用程序在 xamls 中使用数据绑定。 I tried to save the layout of avalon-dock when the application exits, and load the layout when the app start again(Using XmlLayoutSerializer.Deserialize() & Serialize()).
我尝试在应用程序退出时保存 avalon-dock 的布局,并在应用程序再次启动时加载布局(使用 XmlLayoutSerializer.Deserialize() & Serialize())。 The layout is saved and retrived perfectly.
布局被完美地保存和检索。
But all the data-bindings are destroyed, that is, the content of the binded property stays the same as when the application last exits, but data-binding NO LONGER WORKS.但是所有数据绑定都被销毁了,也就是说,绑定属性的内容与应用程序上次退出时的内容保持一致,但数据绑定不再起作用。 Seems avalon-dock deserialize process destroyed the data-binding and the contents are sticked to a permanant value.
似乎 avalon-dock 反序列化过程破坏了数据绑定,并且内容被固定在一个永久值上。
I tried to look for ways of setting what kind of layout data for avalon-dock to save & retrive but nothing found.我试图寻找为 avalon-dock 设置什么样的布局数据来保存和检索但没有找到的方法。 Could any body solve the problem or provide some hints of workarounds?
任何机构都可以解决问题或提供一些解决方法的提示吗?
Thanks.谢谢。
Here's what the binding likes(Here the title is binded):这是绑定喜欢的内容(此处绑定了标题):
<avalon:LayoutAnchorable ContentId="Basic_Docu"
CanHide="False"
CanClose="False"
Title ="{Binding MainPageText.Basic_Tab_Title, Source={StaticResource R}}">
<Frame Name="Basic_Docu_Frame">
</Frame>
</avalon:LayoutAnchorable>
Here's the codes saving and retriving the layouts:这是保存和检索布局的代码:
void Save_LayoutInfo()
{
try
{
string Working_Dir = Environment.CurrentDirectory + "\\layout";
System.IO.Directory.CreateDirectory(Working_Dir);
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(dockingManager);
using (var writer = new StreamWriter(Working_Dir + "\\" + "MainPage"))
{
layoutSerializer.Serialize(writer);
}
}
catch (Exception)
{
;
}
}
void Retrive_LayoutInfo()
{
try
{
string Working_Dir = Environment.CurrentDirectory + "\\layout";
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(dockingManager);
using (var reader = new StreamReader(Working_Dir + "\\" + "MainPage"))
{
layoutSerializer.Deserialize(reader);
}
}
catch (Exception)
{
;
}
}
Use LayoutItemContainerStyleSlector
in 'XAML' to maintain the binding.使用“XAML”中的
LayoutItemContainerStyleSlector
来维护绑定。
for example:例如:
<xcad:DockingManager.LayoutItemContainerStyleSelector>
<pane:PanesStyleSelector>
<pane:PanesStyleSelector.ToolStyle>
<Style TargetType="{x:Type xcad:LayoutAnchorableItem}">
<Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}" />
<Setter Property="ContentId" Value="{Binding Model.ContentId}" />
<Setter Property="FlowDirection" Value="RightToLeft" />
<Setter Property="UseLayoutRounding" Value="False" />
<Setter Property="IconSource" Value="{Binding Model.IconSource}" />
<Setter Property="IsHitTestVisible" Value="True" />
<Setter Property="Title" Value="{Binding Model.Title}" />
</Style>
</pane:PanesStyleSelector.ToolStyle>
<pane:PanesStyleSelector.FileStyle>
<Style TargetType="{x:Type xcad:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Title}" />
<Setter Property="ContentId" Value="{Binding Model.ContentId}" />
<Setter Property="CanClose" Value="{Binding Model.CanClose}" />
<Setter Property="IconSource" Value="{Binding Model.IconSource}" />
<Setter Property="CanFloat" Value="{Binding Model.CanFloat}" />
<Setter Property="Margin" Value="5" />
</Style>
</pane:PanesStyleSelector.FileStyle>
</pane:PanesStyleSelector>
</xcad:DockingManager.LayoutItemContainerStyleSelector>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.