Note that there are some explanatory texts on larger screens.

plurals
  1. PODesign-Time Editor That Works with Application Settings
    primarykey
    data
    text
    <p>I'm trying to create a <strike>custom designer or</strike> UITypeEditor and type converter for a custom type that I've created. I'd like to be able to use this editor in the Application Settings window so that my team and I can define this type for use in the settings of our creations.</p> <p>That this point I've successfully created classes that serialize out to XML, but none of the attempts I've made to implement a designer or type converter have worked and most of the walk-throughs and examples I've been able to find on the topic discuss custom form elements, which is not what I'm after.</p> <p>Ideally what I'd like is something similar to what one encounters when a font is added to the application settings. When editing the value of the setting a dialog allows the developer to easily define the properties of the type, which are then written out to the .config file. This is ideal, but at this point I'd settle for a type converter that actually produces standard values.</p> <p>As I said, I can get the values out to the XML, I just can't figure out how to easily define those values. What approach should I take that would play well with the settings designer?</p> <p>Edit</p> <p>Here's where I'm at right now. I have class that acts as a proxy definition for an OpenFileDialog. The reason for this is outside the scope of this question, but, quickly, it has to do with UI elements that I'm controlling programmatically.</p> <p>Here's the class:</p> <pre><code>Public Class FileSelection Private _selectedFile As String Public Property SelectedFile() As String Get Return _selectedFile End Get Set(ByVal value As String) _selectedFile = value End Set End Property Private _initialDir As String Public Property InitialDirectory() As String Get Return _initialDir End Get Set(ByVal value As String) _initialDir = value End Set End Property Private _title As String Public Property Title() As String Get Return _title End Get Set(ByVal value As String) _title = value End Set End Property Private _filter As String Public Property Filter() As String Get Return _filter End Get Set(ByVal value As String) _filter = value End Set End Property End Class </code></pre> <p>The class in and of itself is doing what it should. But editing the properties of the class at design time is proving painful.</p> <p>I've gotten as far as decorating the class like so: <code>&lt;SettingsSerializeAs(SettingsSerializeAs.Xml)&gt; _ &lt;TypeConverter(GetType(FileSelectionConverter))&gt; _</code></p> <p>With a type converter built, as far as I can, to the specs provided by Microsoft:</p> <pre><code>Public Class FileSelectionConverter Inherits TypeConverter Public Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean If sourceType Is GetType(String) Then Return True End If Return MyBase.CanConvertFrom(context, sourceType) End Function Public Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object If TypeOf value Is String Then Dim v As String() = CStr(value).Split(",") Dim file As New FileSelection file.SelectedFile = Convert.ToString(v(0)) file.InitialDirectory = Convert.ToString(v(1)) file.Filter = Convert.ToString(v(2)) file.Title = Convert.ToString(v(3)) Return file End If Return MyBase.ConvertFrom(context, culture, value) End Function Public Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object If destinationType Is GetType(String) Then Dim file As FileSelection file = CType(value, FileSelection) Return String.Format("{0},{1},{2},{3}", file.SelectedFile, file.InitialDirectory, file.Filter, file.Title) End If Return MyBase.ConvertTo(context, culture, value, destinationType) End Function Public Overrides Function GetStandardValuesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean Return True End Function Public Overrides Function GetStandardValues(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.ComponentModel.TypeConverter.StandardValuesCollection Dim values As New List(Of String) Dim file As New FileSelection file.SelectedFile = "&lt;Selected File&gt;" file.InitialDirectory = "&lt;Initial Directory&gt;" file.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*" file.Title = "&lt;Dialog Title&gt;" values.Add(String.Format("{0},{1},{2},{3}", file.SelectedFile, file.InitialDirectory, file.Filter, file.Title)) Dim svc As New StandardValuesCollection(values) Return svc End Function Public Overrides Function IsValid(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal value As Object) As Boolean Return True End Function End Class </code></pre> <p>The solution builds and run without issue, but I see absolutely nothing in the Settings designer when I add this class as type for use with a setting.</p> <p>What's most frustrating about this is that I have no idea if the converter is working or not. </p> <p>Any guidance would be appreciated.</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.
 

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