Created
April 10, 2019 07:56
-
-
Save darinkes/350b01d1e21f410284abf91c493a2e22 to your computer and use it in GitHub Desktop.
Avalonia Enum UserControl Content Selection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GuiStateTemplate : DataTemplate, IDataTemplate | |
{ | |
[TypeConverter(typeof(EnumConverter))] | |
public GuiState State { get; set; } | |
bool IDataTemplate.Match(object data) | |
{ | |
var enumVal = (GuiState)Enum.Parse(typeof(GuiState), data.ToString()); | |
var result = State == enumVal; | |
Logging.Debug(string.Format("GuiStateTemplate Match: {0} == {1} ({2})", State, enumVal, result)); | |
return result; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl Grid.Row="1"> | |
<UserControl.DataTemplates> | |
<local:GuiStateTemplate State="Searching"><uc:SearchingControl/></local:GuiStateTemplate> | |
<local:GuiStateTemplate State="Idle"><uc:IdleControl/></local:GuiStateTemplate> | |
</UserControl.DataTemplates> | |
<ContentControl Content="{Binding GuiState}"/> | |
</UserControl> |
I met a problem with this way that avalonia throw error like this:
Unable to find default constructor and no non-default one is specified.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is very useful !
Thanks a lot.