Property attributes for Windows 10 Universal custom control? - c#

I'm creating my first Windows 10 Universal Windows Platform (UWP) app. I'm creating a custom templated control to use in it. I've successfully created a DependencyProperty and exposed its value through a standard .NET property. My issue is applying a CategoryAttribute and DescriptionAttribute to the property so it shows in the correct section of the property grid and with the correct description. My custom control project references UniversalWindows. Is there some other reference I need to add?

You may need to create Design-Time library to provide Design-Time metadata. The library should be a WPF C# library.
The library should reference Microsoft.Windows.Design.Extensibility.dll and Microsoft.Windows.Design.Interaction.dll. Then, in the library you should have a class that inherit from IProvideAttributeTable interface to provide metadata attributes.
This is very complex, for more detail see WPF Designer Extensibility .

Related

Modifying SettingsPage.xaml in vs2017 Windows Template Studio c#

I am using Windows Template Studio to create an application with a modifiable theme. Is it possible to add new contents on the settings page? There are 3 themes available currently: light, dark and default. I would like to add another one for example blue. There is an ElementTheme property but I can't modify it since ElementTheme.cs is from metadata.
Windows Template Studio doesn't create an app, it creates the start of an app. What is generated is intended to be a starting point and should be modified as appropriate for your circumstances.
The generated settings page includes the ability to select light or dark theme. Feel free to support either, or neither of these as appropriate. Implementing custom themes should be done in the same way as an app created from a blank template. Just remove anything WTS puts there you don't need or want.
The official UWP docs have some guidance on creating custom themes.
There is also an app in the store to help you create custom themes for your app.
See also, this question about creating custom themes.
There are instructions on further extending the settings page at https://github.com/Microsoft/WindowsTemplateStudio/blob/dev/docs/pages/settings.md

Binding from code to a custom attached property in WinRT/UWP

I'm trying to create a binding from code in a library that targets multiple frameworks (WPF, WinRT, UWP etc), and I'm hitting a brick wall. The property I'm trying to bind to is a custom attached property. In WPF, I can pass the DependencyProperty itself as the binding path:
new PropertyPath(MyClass.MyAttachedProperty)
But in WinRT the PropertyPath class only accepts a string. I tried to pass the name of the property like this:
new PropertyPath("(MyClass.MyAttachedProperty)")
but of course it doesn't work, since my class is not in the default namespace. In XAML I could map the namespace to a prefix and use that prefix, but as far as I know it's not possible to do this from code.
Is there any way to create this binding in code?
Good question, after researching and discussing we've confirmed that in UWP, we cannot programmatically binding to custom attached property. Sadly.
You may submit a request to add this new features for development through the Windows Feedback tool.
It looks as though there may be a solution here, which involves using XamlReader.Load and a resource dictionary containing the binding, to get the loader to do the work for you.
How can I bind to a custom attached property in c# from code behind in a windows store app?

WPF CustomControl in dll

Is it possible to add definition of WPF Custom Control to dll?
There is no such a template in Visual Studio 2015. Only template "WPF User Control" is avaiable, but I don't want to create control from scratch but modernize existing standard control.
The following project types exist that might fit your needs:
WPF Custom Control Library: Custom controls extend one of the WPF control base classes and provide additional functionality through code.
WPF User Control Library: A user control is technically a normal content control which you can extend in some parts in the code but usually it is extended by placing other controls inside of it.
See this answer for more information: What is the difference between a User Control Library and a Custom Control Library?
If I understand you correct, you want to create a User Control based on XAML. In my Visual Studio, this template is called "User Control WPF" and yes, you can add it to a Dll.
To modernize an existing control it might be simple to modifiy the style and ControlTemplate of this control. You can extract style and control template using Blend and then modify it to your needs.

Accessing a Custom Renderer Instance from Xamarin Forms Element Shared Code

I am creating a component that uses a custom renderer on each platform. Let's just call it a SpecialButton element. BindableProperty works fine for values but I also want to allow a user to invoke operations on the renderer from shared code (call methods on the renderer from the Forms control code). I was looking at DependencyService as a possible solution but I don't think that will work because it is possible for multiple buttons to appear on the same page so I need the specific renderer instance that was created and linked to my Xamarin Forms element.
So, is there an elegant way for my Xamarin Forms control element to
get access to the custom renderer that was instantiated by the Forms
framework?
I had thought about exposing a property on the control and letting the renderer set itself to the property in its constructor but this feels hacky and also exposes it to the user of the control which I don't want to do.
I think I figured out a solution. I didn't realize the MessagingCenter had a source parameter which can be used to specify the element property.
MessagingCenter.Subscribe(this, "DoOperation", myButton => DoOperation(), Element);

How do I add Windows Form Designer support to a custom control?

I am new to the concept of custom controls, and until recently my experience has been limited to extending controls that already exists.
In Visual Studio, how do I add support for my custom controls in the form of Designer Drop Downs and forms?
This picture below identifies the kind of components I am wishing to create for my custom controls.
I'd recommend reading Extending Design Support on MSDN. In this case, you want a custom designer for your type, which can be specified via the DesignerAttribute decorating the type. For details, see Custom Designers.

Categories