Closed JoshWobbles closed 5 years ago
Can you show your XAML? And wich DLL I need to include?
If by dll to include you mean my user control, it is just a slight modification to the generic MediaElement to allow looping;
public class LoopableMediaElement : MediaElement
{
public bool Loop
{
get { return (bool)GetValue(LoopProperty); }
set { SetValue(LoopProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty LoopProperty =
DependencyProperty.Register("Loop", typeof(bool), typeof(LoopableMediaElement), new PropertyMetadata(true));
public LoopableMediaElement()
{
this.MediaEnded += LoopableMediaElement_MediaEnded;
}
private void LoopableMediaElement_MediaEnded(object sender, RoutedEventArgs e)
{
if (Loop)
{
this.Position = TimeSpan.FromMilliseconds(1);
}
}
}
Beyond that everything is plain Jane and my IDE XAML is pretty much identical to the sample code provided here.
Could not reproduce... Could you not debug it? Or use PDB's so we have a Line Number?
Line 61, TimeSpanEditor.xaml.cs;
var value = (TimeSpan) PropertyNode.DesignerValue;
but during the debug even though it throws a NullRef, I can see that it does in fact have a value when i mouse over during the break. Race condition possibly?
For reference I have a .mov video in the MediaElement that is auto playing if that makes any difference when you tested.
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=ICSharpCode.WpfDesign.Designer StackTrace: at ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.TimeSpanEditor.NumberEditor_DataContextChanged(Object sender, DependencyPropertyChangedEventArgs e) in C:\projects\wpfdesigner\WpfDesign.Designer\Project\PropertyGrid\Editors\TimeSpanEditor.xaml.cs:line 61
Console outputs:
ICSharpCode.WpfDesign.PropertyGrid.PropertyNode.DesignerValue.**get** returned null.
But DesignerValue is definitely not null when I mouse over it during the debug break
Ok, some more troubleshooting, this doesn't seem to throw an error until I save and reload the xaml. Despite the XAML being identical from the first save to consecutive saves, It only throws the error after the document has been loaded using designSurface.LoadDesigner(xmlReader, loadSettings);
Figured id bring the discussion back to this thread.
I tried a new project using the demo code and still same error. The XAML below will alwayse throw an exception when trying to edit a property in the property control.
private static string xaml = @"<Grid
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
mc:Ignorable=""d""
x:Name=""rootElement"" Background=""White"">
<MediaElement Source=""C:\Users\jhebb\Videos\2019-03-15 10-25-29.mp4""/>
</Grid>";
Make sure to change the Source path to a valid local video.
your source does not contain any code...
@jogibear9988 that was weird, I just pushed again, looks like its up now, not much to it though like I said, the difference is just loading xaml that has a mediaelement with a video source
In this example I am actually able to see the DesignerValue
property is infarct null, a ?? at line 61 in TimeSpanEditor.xaml.cs may be a workaround for the issue, but the actual fix may be seeing why the property does not properly populate after parsing from XAML using your LoadDesigner
.
Problem is the IsAmbiguous check in PropertyNode. It return true, cause the Video is Playing and the time is read 2 times and is then different!
So the TimeSpan Editor should also work when the value is null, I'll fix it
AWSOME! I was just digging into the TypeEditor seeing if it was possible to override the TimeSpanEditor for my use case, but if the problem was in fact reproducible then this is even better!
Looking forward to the NuGet push to test it out in my production project but at first glance looks like that should catch the issue just fine!
Just out of curiosity though now that I see that this editor does implement some sort of TypeEditor attributes, how would I go about implementing my own, does the property grid automatically recognize that attribute? is there a way to override an existing TypeEditor like for example in this case if I needed to do so?
I think the last one should be used.
You need to register your assembly via EditorManger.RegisterAssembly
In my WPF Application I added complete PropertyPages depending on the Type, and use the WpfDesigner Propertygrid as a fallback for unpopular Properties. I'll look to extend one of the samples to show how easy this is, especially when you use the DesignItemBinding
when using a MediaElement, I get the following exception whenever I try to select the control in the design view.
This only happens when selecting an already placed control, not when drawing or editing it initially. Must click out then back in.