Replace Button with Text or Button Content.

Hi Team,

I am Using WPF MVVM

My sample code is given below :

XAML :

<syncfusion:GridTemplateColumn MappingName="Create Demat Account" ShowHeaderToolTip="True" Width="130"                       syncfusion:FocusManagerHelper.WantsKeyInput="True" >
                                <syncfusion:GridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        
                                        <Button Content="{Binding CreateDematAccountBtn}" ToolTip="Create Demat Account" Command="{Binding DataContext.OnCreateDemat,ElementName=dgKYCUser}" CommandParameter="{Binding}"/>
                                    </DataTemplate>
                                </syncfusion:GridTemplateColumn.CellTemplate>
                            </syncfusion:GridTemplateColumn>


ViewModel : 
        
        private string _CreateDematAccountBtn = "Create Demat Account";
        public string CreateDematAccountBtn
        {
            get
            {
                return _CreateDematAccountBtn;
            }
            set
            {
                SetProperty(ref _CreateDematAccountBtn, value);
            }
        }



 CreateDematAccountBtn = SomeObject.StringContent;



After using this my button content shows empty.

The working should be like after clicking on button the button content should change or Button should replace with just text.
Is there any way to change button content or replace button with just text on that same row.

Here is the Screenshot of My UI



please help me this.

Thank You.



1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team July 10, 2020 04:23 PM UTC

Hi Devendragrv13,

Thank you for contacting Syncfusion support.

 
Your requirement can be achieved by using Button clicked in column content can be changed by command. Please refer the below code snippet,

 
XAML Code Snippet: 
 
<syncfusion:GridTemplateColumn HeaderText="CustomerName" MappingName="CustomerName" > 
                    <syncfusion:GridTemplateColumn.CellTemplate> 
                        <DataTemplate>                            
                            <Button x:Name="btnButton"  Content="{Binding CustomerName}"  Width="100" Height="50" syncfusion:FocusManagerHelper.FocusedElement="True" 
                     Command="{Binding Path=DataContext.RowDataCommand,ElementName=sfDataGrid}"  
                     CommandParameter="{Binding ElementName=btnButton}"/>                              
                        </DataTemplate> 
                    </syncfusion:GridTemplateColumn.CellTemplate> 
</syncfusion:GridTemplateColumn> 
 
C# Code Snippet: 
 
public void ChangeCanExecute(object obj) 
{ 
            var button = (obj as Button); 
 
            //Here your customized content can set to button content 
            button.Content = "ContentChanged"; 
} 
 

We hope this helps. Please let us know, if you require further assistance on this. 

Regards,
Vijayarasan S
 


Marked as answer
Loader.
Up arrow icon