Click here to Skip to main content
15,513,143 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I crated an icon in xaml file. Something like
<UserControl x:Class="WpfApp2.access_point"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfApp2"
             >
    <Grid>
        <Canvas x:Name="point" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="24" Height="24">
            <Path Data="M4.93,4.93C3.12,6.74 2,9.24 2,12C2,14.76 3.12,17.26 4.93,19.07L6.34,17.66C4.89,16.22 4,14.22 4,12C4,9.79 4.89,7.78 6.34,6.34L4.93,4.93M19.07,4.93L17.66,6.34C19.11,7.78 20,9.79 20,12C20,14.22 19.11,16.22 17.66,17.66L19.07,19.07C20.88,17.26 22,14.76 22,12C22,9.24 20.88,6.74 19.07,4.93M7.76,7.76C6.67,8.85 6,10.35 6,12C6,13.65 6.67,15.15 7.76,16.24L9.17,14.83C8.45,14.11 8,13.11 8,12C8,10.89 8.45,9.89 9.17,9.17L7.76,7.76M16.24,7.76L14.83,9.17C15.55,9.89 16,10.89 16,12C16,13.11 15.55,14.11 14.83,14.83L16.24,16.24C17.33,15.15 18,13.65 18,12C18,10.35 17.33,8.85 16.24,7.76M12,10A2,2 0 0,0 10,12A2,2 0 0,0 12,14A2,2 0 0,0 14,12A2,2 0 0,0 12,10Z" />
        </Canvas>
    </Grid>
</UserControl>

Don't worry about the shape. Now I want to reference it in another view in a button. The code is inaccurate but it seems like:
<Button Style="{Binding AStyle}">
     <ContentControl Content=Template="{DynamicResource point}">
</Button>


My question is the button maybe enabled/disabled at the running time. Disable means it is grayed out. Not sure how to do it?

What I have tried:

Thinking about trigger. But still no clue.
Posted
Updated 19-Dec-17 10:33am
v3

The most appropriate way to hook up a button is through a command binding. The command has a CanExecute property that is automatically hooked to the button's IsEnabled property. Depending on what ICommand implementation you use, the code to update the CanExecute can vary.

NOTE: I prefer the PRISM DelegateCommand, but MVVMLight has a popular RelayCommand too.

The other most common way to hook up the disabling is through a binding to the IsEnabled property itself. You can use converters to test whatever condition you want. For example, you can bind to a Count property than hook up a converter that is a IntLessThanTenConverter to return false if the bound Count is ever more than ten.
 
Share this answer
 
can you explain clearly what is your doubt ?

to disable a button dynamically at run time base don your requirement you can use triggers when it is onmouseover using this property you can you can disable it .
another way is you can write it in code behinid.
button.isenabled =false;// here it disables the button

button.isenables=true;//here it enables the bubtton
 
Share this answer
 
v2
Comments
Member 12658724 19-Dec-17 7:56am    
I updated the code. Let say if the records reach 10, we can't add new record to the database then we have to disable the button.
saimanisha 20-Dec-17 6:32am    
suppose you make a count of each record
if count > 10 then in the condition you write code for disabling that button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900