first of all - I'm sorry if it's a duplicate - been looking around for awhile and couldn't find an answer to that,
We're using caliburn.micro so the solution must be using this tool.
We have a view that is consisted of 9 buttons, however - not all of them will be visible in the same time, it depends on events on the system. Each button visibility to either visible or collapsed based on current status but since it is a large number of buttons, and may increase in the future I'd rather have a single function to do this (receiving a name or an enum and returning visibility) rather than having a large amount of properties to bind each button to.
Is it even an option? I couldn't seem to find a way of doing it in any conventional way.
Since the events are being received from outside the software we're developing doing this on the view level is not really an option (or at least - not a right one)
Edit: Here's a snippet of the view that I wish to modify:
<Grid Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<uiviews:PhonePadView Grid.Column="0" x:Name="DestinationDn" cal:Bind.Model="UI.ViewModels.PhonePadViewModel" />
<Button Grid.Column="1" Content="Dial" Style="{StaticResource PhonePadBasicFunctionsButtons}" x:Name="MakeCall" Visibility="{Binding btnMakeCallVisibility}" />
<Button Grid.Column="1" Content="Answer" Style="{StaticResource PhonePadBasicFunctionsButtons}" x:Name="AnswerCall" Visibility="{Binding btnAnswerCallVisibility}" />
<Button Grid.Column="1" Content="Hang-up" Style="{StaticResource PhonePadBasicFunctionsButtons}" x:Name="ReleaseCall" Visibility="{Binding btnReleaseCallVisibility}" />
<Button Grid.Column="1" Content="Hold" Style="{StaticResource PhonePadBasicFunctionsButtons}" x:Name="HoldCall" Visibility="{Binding btnHoldCallVisibility}" />
</Grid>
As you can see, I need to have a different property for each of the buttons, and I refuse to believe this is the only way, I do have a property holding the current status (phone is ringing, in a call, dialing etc.) and it's easy to have a function on the VM to tell which button should be visible and which shouldn't, and on top of it we currently have 9 buttons but it may just as easily expand more, so I'm looking for the most modular code possible here
Converter
or aMultiValueConverter
to decide the visibility? If only ViewModel can decide these based on complex states, then try reducing it into a computed property or two likeCurrentVisibleButtonGroup
or something and make it an enum or a number. based on that property, decide which buttons should be visible using a simple value converter plugged in between. – ArthurCommand
andCommandParameter
properties built in, and that includesButton
andMenu
items. – Arthur