Completed

C# - WPF DataGrid with dynamic button on each row - Help for DataTemplateSelector

I wrote a small application, which lists some files containing XML-snippets from a folder into a DataGrid.

Now I want to add a button with the label "Install" to the first column, which gives the user the possibility to install the snippet to another file. If this snippet is already included into the file, the button should change to "Uninstall". Therefore I added the following to my XAML:

````xaml

...

<[login to view URL]>

<local:ButtonTemplateSelector x:Key="buttonTemplateSelector">

<local:[login to view URL]>

<DataTemplate>

<Button x:Name="btn_installSnippet" Click="btn_installSnippet_Click">Install</Button>

</DataTemplate>

</local:[login to view URL]>

<local:[login to view URL]>

<DataTemplate>

<Button x:Name="btn_uninstallSnippet" Click="btn_uninstallSnippet_Click">Uninstall</Button>

</DataTemplate>

</local:[login to view URL]>

</local:ButtonTemplateSelector>

</[login to view URL]>

...

<DataGrid x:Name="dataGrid_newViews" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="148" Margin="40,152,0,0" VerticalAlignment="Top" Width="685" AutoGenerateColumns="True" SelectedCellsChanged="Datagrid_SelectedCellsChanged" CanUserAddRows="false" Grid.ColumnSpan="2">

<[login to view URL]>

<DataGridTemplateColumn Header="Button" CellTemplateSelector="{StaticResource buttonTemplateSelector}" />

</[login to view URL]>

</DataGrid>

````

Now I have problems with the code part, where the correct DataTemplate should be selected depending on a condition.

````c#

public class ButtonTemplateSelector : DataTemplateSelector

{

public DataTemplate InstallButtonTemplate { get; set; }

public DataTemplate UninstallButtonTemplate { get; set; }

public override [login to view URL] SelectTemplate(object item, [login to view URL] container)

{

if(!CheckIfXmlAlreadyInstalled(<data>)

{

return InstallButtonTemplate;

}

else {

return UninstallButtonTemplate;

}

}

````

I do not know how to pass the correct values to my condition part.

Who can help me?

Skills: C# Programming, WPF, .NET, C++ Programming

See more: paypal dynamic button, datagrid radio button extjs, create dynamic button actionscript example, button column in datagridview c# wpf, wpf datagrid add new row on button click, wpf xaml datagrid button, datagrid button column wpf c#, wpf datagrid edit row on button click, wpf datagrid button click get row, how to add button in gridview in c#, c# wpf datagrid button, dynamic button action script, actionscript dynamic button example, flash create dynamic button actionscript, dynamic button actionscript, wpf media player button, paypal dynamic button encrypted, flash dynamic text row, datagrid add delete row extjs, paypal dynamic button encryption php

About the Employer:
( 9 reviews ) Hamburg, Germany

Project ID: #27454627

Awarded to:

wangcaocao

Hi! How are you? I am interested in your project. I have been developed many C# WPF projects for 10 years. I read your description in detail and can help you well. Please contact me. Best Regard

$30 USD in 1 day
(34 Reviews)
5.5

4 freelancers are bidding on average $28 for this job

wangdao5211

Hi, bro! I have read your requirement and I noticed that I am appropriate to this project. As a skillful software developer, I have rich experience with XML data processing in WPF. I promise I will finish this project More

$30 USD in 2 days
(15 Reviews)
4.1
barmalasharma

Hi I'm interested of your post and exciting to do the over your project. please let me know your availability for further discussion

$30 USD in 2 days
(0 Reviews)
0.0
geekydevss

Hi, I am interested and I was actually looking for this sort of project too. I want to help you develop this app and fix your error. I have worked with WPF and XML files so I think I am the right person for the job whi More

$20 USD in 1 day
(0 Reviews)
0.0