版本:1.30.18
模块:自定义窗口
Xaml代码:
<Grid Margin="10">
<StackPanel Margin="15 20">
<DataGrid Name="DG1" ItemsSource="{Binding [GridItemsSource], Mode=OneWay}" AutoGenerateColumns="False" IsReadOnly="True" >
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Current?" Binding="{Binding IsCurrent}"/>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
<DataGridTextColumn Header="Author" Binding="{Binding Author}" />
<DataGridTextColumn Header="Last Commit Time" Binding="{Binding LastCommitTime}"/>
<DataGridTextColumn Header="Last Commit Message" Binding="{Binding LastCommitMessage}"/>
</DataGrid.Columns>
</DataGrid>
<Button Margin="10" qk:Att.Action="close:result" Style="{StaticResource ButtonPrimary}" Width="50">
关闭
</Button>
</StackPanel>
</Grid>
辅助C#代码:
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Collections.Generic;
using MessageBox = System.Windows.Forms.MessageBox;
using Newtonsoft.Json;
using Quicker.Public;
public static void OnWindowCreated(Window win, IDictionary<string, object> dataContext,
ICustomWindowContext winContext
){
var definition = new []{
new {
Name = string.Empty,
Author = string.Empty,
LastCommitTime = string.Empty,
LastCommitMessage = string.Empty,
IsCurrent = false,
}};
dataContext["GridItemsSource"] = JsonConvert.DeserializeAnonymousType((string)dataContext["GridItemsSourceJson"], definition);
}
"A TwoWay or OneWayToSource" binding cannot work on the readonly property 'IsCurrent'
InvalidOperationException
at MS.Internal.Data.PropertyPathWorker.CheckReadOnly(Object item, Object info)
at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32 k, Object newO, Object parent)
at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
at MS.Internal.Data.ClrBindingWorker.AttachDataItem()
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Run(Object arg)
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
可以是列表。
核心点是没有捕捉WPF解析异常,导致Quciker进程崩溃,动作组合都没来得及保存就退出了
感谢! AppDomain我还没试过,等试试看。 捕获异常目前是就是那个统一的弹框报错了,不过没法判断是自定义c#里的代码异常,处理的不是很理想。