Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF DataTemplate multibinding causes FrameworkElement.ApplyTemplate() to throw NullReferenceException
    primarykey
    data
    text
    <p>To give some context : I have a list of items, and i draw an image for each of them. They all have a black border but the one that is bound to the same object than a given "Brush" property. That one has a red border to show which brush is selected.</p> <p>here is the code</p> <pre><code>&lt;ItemsControl ItemsSource="{Binding}"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;StackPanel Orientation="Horizontal"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Border BorderBrush="Black" BorderThickness="2 2 2 2"&gt; &lt;Border.Style&gt; &lt;Style TargetType="{x:Type Border}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Value="True"&gt; &lt;DataTrigger.Binding&gt; &lt;MultiBinding Converter="{StaticResource ResourceKey=AreEqualConverter}"&gt; &lt;Binding/&gt; &lt;Binding ElementName="Me" Path="Brush"/&gt; &lt;/MultiBinding&gt; &lt;/DataTrigger.Binding&gt; &lt;Setter Property="BorderBrush" Value="Red"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Border.Style&gt; &lt;Image Source="{Binding}" Height="{Binding ElementName=TilePreviewSize, Path=Value}" Width="{Binding ElementName=TilePreviewSize, Path=Value}" RenderOptions.BitmapScalingMode="NearestNeighbor" MouseDown="OnBrushMouseDown"/&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; </code></pre> <p>I get the follow error "NullReferenceException : Object reference not set to an instance of an object." when the following block of code is uncommented. Can't figure out what is the problem.</p> <pre><code>&lt;Style TargetType="{x:Type Border}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Value="True"&gt; &lt;DataTrigger.Binding&gt; &lt;MultiBinding Converter="{StaticResource ResourceKey=AreEqualConverter}"&gt; &lt;Binding/&gt; &lt;Binding ElementName="Me" Path="Brush"/&gt; &lt;/MultiBinding&gt; &lt;/DataTrigger.Binding&gt; &lt;Setter Property="BorderBrush" Value="Red"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>If you want to see the converter's code, here it is (quite simple)</p> <pre><code>public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values.Length &lt; 2) throw new NotSupportedException(); var obj = values[0]; for (int i = 1; i &lt; values.Length; ++i) if (!values[i].Equals(obj)) return false; return true; } </code></pre> <p>Here is the stacktrace or the error:</p> <pre><code> at IntegratorUI.Contexts.RoomContext.System.Windows.Markup.IStyleConnector.Connect(Int32 connectionId, Object target) in [...] line 138 at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter) at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter) at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField) at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren) at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate) at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container) at System.Windows.FrameworkElement.ApplyTemplate() at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.StackPanel.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run() at IntegratorUI.App.Main() in D:\trollmeme\integrator\IntegratorUI\obj\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() </code></pre> <p>Thanks for helping me sort this out!</p> <p>Nic</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload