This is a migrated thread and some comments may be shown as answers.

[Solved] Button in a grid

3 Answers 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Deepak Garla
Top achievements
Rank 1
Deepak Garla asked on 26 Oct 2009, 06:47 PM
Hi,

I have placed a button in a grid.I want to change the image source of the button dynamically in Xaml.cs. How do i go about it?i will also be needing the image source of the image on the button dynamically in xaml.cs.

Help me with this.

Regards,
Deepak Garla.

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 28 Oct 2009, 07:46 AM
Hello Deepak Garla,

Where and how have you placed this button? We have almost no clues regarding your setup.

Please, send us a sample project.

Best wishes,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Deepak Garla
Top achievements
Rank 1
answered on 30 Oct 2009, 11:13 AM

Hi Ross,

My code is like this

 

XAML PAGE

 

 

<

 

Grid x:Name="LayoutRoot" Background="White">

 

<StackPanel Margin="1,24,8,6" x:Name="stkPanelradgrdUserdetails" >

 

 

 

<telerikGridView:RadGridView x:Name="radgrdUserdetails" RowIndicatorVisibility="Collapsed" Margin="0,0,0,0" Visibility="Visible" >

 

 

 

 

 

 

 

<telerikGridView:RadGridView.Columns>

 

 

 

 

<telerikGridView:GridViewColumn Header="" Width="40" IsVisible="True" x:Name="Dum">

 

 

 

 

<telerikGridView:GridViewColumn.CellTemplate>

 

 

 

 

<DataTemplate x:Name="dtTemp02">

 

 

 

 

<Button x:Name="btnEdit" Height="25" Width="40" BorderThickness="0" Background="Transparent" Content="Edit" Click="btnEdit_Click">

 

 

 

 

<!--<Image x:Name="imgEdit" Height="20" Width="40"/>-->

 

 

 

 

</Button>

 

 

 

 

</DataTemplate>

 

 

 

 

</telerikGridView:GridViewColumn.CellTemplate>

 

 

 

 

</telerikGridView:GridViewColumn>

 

 

 

 

<telerikGridView:GridViewColumn Header="" Width="47" IsVisible="True">

 

 

 

 

<telerikGridView:GridViewColumn.CellTemplate>

 

 

 

 

<DataTemplate x:Name="dtTemp03">

 

 

 

 

<Button x:Name="btnDELETE" Height="25" Width="40" BorderThickness="0" Background="Transparent" Content="Del" HorizontalAlignment="Center" Click="btnDELETE_Click_1">

 

 

 

 

<!--<Image x:Name="Delete" Source="Images/Delete.PNG" Height="20" Width="45" />-->

 

 

 

 

</Button>

 

 

 

 

</DataTemplate>

 

 

 

 

</telerikGridView:GridViewColumn.CellTemplate>

 

 

 

 

</telerikGridView:GridViewColumn>

 

 

 

 

<telerikGridView:GridViewDataColumn Header="User Name" IsReadOnly="True" DataMemberPath="UserName" TextWrapping="Wrap" Width="150"/>

 

 

 

 

<telerikGridView:GridViewDataColumn Header="Email Id" IsReadOnly="True" DataMemberPath="UserEmailId" Width="220" TextWrapping="Wrap"/>

 

 

 

 

 

</telerikGridView:RadGridView.Columns>

 

 

 

 

</telerikGridView:RadGridView>

 

 

 

 

 

</StackPanel>

 

 

 

 

 

 

 

</Grid>

 

</

 

 

UserControl>

 

 

 

 


XAML.cs



 

private

 

 

void btnEdit_Click(object sender, RoutedEventArgs e)

 

{

 

 


    if
((sender as Button).Content.ToString() == "Edit")

 

    {

 

        (sender

 

as Button).Content = "sav";

 

 

 

        var button2 = ((Button)sender).ParentOfType<GridViewRow>().ChildrenOfType<Button>().Where(b => b.Content.Equals    
(
"Del")).FirstOrDefault();

 

    button2.Content =

 

"can";

 

 

 

 

    //Business logic:My business logic is implemented here

 

 

 

 

 

 

 

    }

 

else if ((sender as Button).Content.ToString() == "sav")

 

    {

    (sender

 

as Button).Content = "Edit";

 

 

 

    var button2 = ((Button)sender).ParentOfType<GridViewRow>().ChildrenOfType<Button>().Where(b => b.Content.Equals("can")).FirstOrDefault();

 

    button2.Content =

 

"Del";

 

 

 

 

    //Business logic:My business logic is implemented here

 

 

 

 

 

    }

}

 

 

private void btnDELETE_Click_1(object sender, RoutedEventArgs e)

 

{

 

 

    if ((sender as Button).Content.ToString() == "Del")

 

    {

 

 

 

    //Business logic:My business logic is implemented here

 

 

    }

 

 

    else if ((sender as Button).Content.ToString() == "can")

 

    {

    (sender

 

as Button).Content = "Del";

 

 

 

    var button2 = ((Button)sender).ParentOfType<GridViewRow>().ChildrenOfType<Button>().Where(b => b.Content.Equals("sav")).FirstOrDefault();

 

    button2.Content =

 

"Edit";

 

 

 

 

    //Business logic:My business logic is implemented here

 

 

    }

    }

 

  }

 


Now my code is working fine with text on buttons...how ever i am not  able to use images on buttons instead of text and achieve  the same funcitionality.i need help with this.


Regards,
Deepak Garla. 











 

 

0
Rossen Hristov
Telerik team
answered on 02 Nov 2009, 10:54 AM
Hi Deepak Garla,

I have attached a sample project. Please, examine it and let me know if you have any other questions.

Regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Deepak Garla
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Deepak Garla
Top achievements
Rank 1
Share this question
or