Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET 4.5 Metro Application DependencyProperty
    primarykey
    data
    text
    <p>I cant get <code>DependencyProperty.Register</code> to work. </p> <p>It requires <code>(string, string, string, PropertyMetadata)</code> instead of <code>string, Type, Type, UIPropertyMeatdata)</code>... </p> <p>I changed the UI-PropertyMetadata part but can't get string part of it to work. I tried <code>typeof(T).ToString()</code> and just <code>"T"</code> but it doesn't work. </p> <p>My code looks like this</p> <pre><code>public ObservableCollection&lt;RingSegment&gt; RingSegments { get { return (ObservableCollection&lt;RingSegment&gt;)GetValue(RingSegmentsProperty); } set { SetValue(RingSegmentsProperty, value); } } public static readonly DependencyProperty RingSegmentsProperty = DependencyProperty.Register( "RingSegments", typeof(ObservableCollection&lt;RingSegment&gt;), typeof(MainPage), new PropertyMetadata(new ObservableCollection&lt;RingSegment&gt;())); </code></pre> <p>And errors that i get</p> <p><code>Error 1 The best overloaded method match for 'Windows.UI.Xaml.DependencyProperty.Register(string, string, string, Windows.UI.Xaml.PropertyMetadata)' has some invalid arguments C:\Users\aleksandar.toplek\documents\visual studio 11\Projects\Project - XX\XX\MainPage.xaml.cs 21 68 XX</code></p> <p><code>Error 2 Argument 2: cannot convert from 'System.Type' to 'string' C:\Users\aleksandar.toplek\documents\visual studio 11\Projects\Project - XX\XX\MainPage.xaml.cs 22 20 XX</code></p> <p><code>Error 3 Argument 3: cannot convert from 'System.Type' to 'string' C:\Users\aleksandar.toplek\documents\visual studio 11\Projects\Project - XX\XX\MainPage.xaml.cs 22 63 XX</code></p> <p>-- EDIT --</p> <p>When I do this</p> <pre><code>public static readonly DependencyProperty RingSegmentsProperty = DependencyProperty.Register( "RingSegments", "ObservableCollection&lt;RingSegment&gt;", "MainPage", new PropertyMetadata(new ObservableCollection&lt;RingSegment&gt;())); </code></pre> <p>Code compiles but throws exception in runtime</p> <p><code>A first chance exception of type 'System.TypeInitializationException' occurred in mscorlib.dll</code></p> <p>in file <code>XamplTypeIngo.g.cs</code></p> <pre><code>System.TypeInitializationException was unhandled by user code Message=The type initializer for 'XX.MainPage' threw an exception. Source=mscorlib TypeName=XX.MainPage StackTrace: at System.Runtime.CompilerServices.RuntimeHelpers._RunClassConstructor(RuntimeType type) at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle type) at Disk_Visualizer.XamlTypeInfo.XamlUserType.RunInitializer() in c:\Users\aleksandar.toplek\Documents\Visual Studio 11\Projects\Project - XX\XX\obj\Debug\XamlTypeInfo.g.cs:line 277 InnerException: System.NullReferenceException Message=Object reference not set to an instance of an object. Source=Windows.UI.Xaml StackTrace: at Windows.UI.Xaml.DependencyProperty.Register(String name, String propertyTypeName, String ownerTypeName, PropertyMetadata typeMetadata) at Disk_Visualizer.MainPage..cctor() in c:\Users\aleksandar.toplek\Documents\Visual Studio 11\Projects\Project - XX\XX\MainPage.xaml.cs:line 21 InnerException: ... </code></pre>
    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.
 

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