Click here to Skip to main content
15,890,336 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Problem in Pausing a Storyboard in WPF ? Pin
Mohammad Dayyan15-Feb-10 5:05
Mohammad Dayyan15-Feb-10 5:05 
QuestionButton not firing in WPF Toolkit datagrid Pin
Member 454056412-Feb-10 8:12
Member 454056412-Feb-10 8:12 
AnswerRe: Button not firing in WPF Toolkit datagrid Pin
AspDotNetDev12-Feb-10 20:41
protectorAspDotNetDev12-Feb-10 20:41 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
Hannes Larsson17-Feb-10 20:36
Hannes Larsson17-Feb-10 20:36 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
AspDotNetDev17-Feb-10 21:42
protectorAspDotNetDev17-Feb-10 21:42 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
Hannes Larsson17-Feb-10 21:53
Hannes Larsson17-Feb-10 21:53 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
AspDotNetDev17-Feb-10 22:03
protectorAspDotNetDev17-Feb-10 22:03 
GeneralRe: Button not firing in WPF Toolkit datagrid [modified] Pin
Hannes Larsson17-Feb-10 23:03
Hannes Larsson17-Feb-10 23:03 
Ok, so i have created a small project that displayes my issue, but i can't upload the whole project as zip, so i have to add all the code:

It is a normal wpf project (.NET 4, but 3.5 should work as well, just need wpf toolkit)
Also i use delegate commands fron WPF PRISM so these two assemblies are needed:
Microsoft.Practices.Composite.dll
Microsoft.Practices.Composite.Presentation.dll

MainWindow.xaml
<Window x:Class="DataGridButtonCommandTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="300" Width="400" x:Name="MyView">
    <Grid DataContext="{Binding}">
        <Grid.RowDefinitions>
            <RowDefinition Height="224*" />
            <RowDefinition Height="45" />
        </Grid.RowDefinitions>
        <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=MyItems}" Margin="10,10,10,0" CanUserAddRows="False" CanUserDeleteRows="False" Grid.RowSpan="1">
        <DataGrid.Columns>
          <DataGridTemplateColumn Header="Title" Width="100">
            <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding ItemTitle}"/>
              </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
          </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Button" Width="100">
                    <DataGridTemplateColumn.CellTemplate>
                      <DataTemplate>
                        <Button Content="{Binding ButtonTitle}" Command="{Binding ElementName=MyView, Path=DataContext.ShowMyPopUp}"/>
                      </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
      </DataGrid>
      <StackPanel Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Bottom" Margin="10">
        <TextBlock Text="Button with same command binding: " VerticalAlignment="Center" Margin="0,0,5,0"/>
        <Button Content="Show popup" Command="{Binding ElementName=MyView, Path=DataContext.ShowMyPopUp}" Width="75"/>
      </StackPanel>
    </Grid>
</Window>


MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DataGridButtonCommandTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new PresentationModel();
        }
    }
}


PresentationModel.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Presentation.Commands;

namespace DataGridButtonCommandTest
{
    public class PresentationModel : INotifyPropertyChanged
    {
        private ObservableCollection<MyItem> myItems;
        public event PropertyChangedEventHandler PropertyChanged;
        public DelegateCommand<object> ShowMyPopUp { get; private set; }

        public PresentationModel()
        {
            MyItems = new ObservableCollection<MyItem>
                          {
                              new MyItem{ItemTitle = "First", ButtonTitle = "Show popup"}, 
                              new MyItem{ItemTitle = "Second", ButtonTitle = "Show popup"},
                              new MyItem{ItemTitle = "Third", ButtonTitle = "Show popup"}
                          };

            ShowMyPopUp = new DelegateCommand<object>(OnShowMyPopUp);
        }

        private void OnShowMyPopUp(object obj)
        {
            var popUp = new PopUpWindow();
            popUp.ShowDialog();
        }

        public ObservableCollection<MyItem> MyItems
        {
            get
            {
                return myItems;
            }
            set
            {
                if(!Equals(myItems, value))
                {
                    myItems = value;
                    OnPropertyChanged("MyItems");
                }
            }
        }

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    public class MyItem
    {
        public string ItemTitle { get; set; }
        public string ButtonTitle { get; set; }
    }
}


PopUpWindow.xaml
<Window x:Class="DataGridButtonCommandTest.PopUpWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="PopUpWindow" Height="300" Width="300">
    <Grid>
      <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="It works!!!"/>
    </Grid>
</Window>


PopUpWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DataGridButtonCommandTest
{
    /// <summary>
    /// Interaction logic for PopUpWindow.xaml
    /// </summary>
    public partial class PopUpWindow : Window
    {
        public PopUpWindow()
        {
            InitializeComponent();
        }
    }
}
modified on Thursday, February 18, 2010 5:10 AM

GeneralRe: Button not firing in WPF Toolkit datagrid Pin
AspDotNetDev17-Feb-10 23:13
protectorAspDotNetDev17-Feb-10 23:13 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
Hannes Larsson17-Feb-10 23:15
Hannes Larsson17-Feb-10 23:15 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
AspDotNetDev17-Feb-10 23:42
protectorAspDotNetDev17-Feb-10 23:42 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
AspDotNetDev18-Feb-10 0:02
protectorAspDotNetDev18-Feb-10 0:02 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
Hannes Larsson18-Feb-10 1:39
Hannes Larsson18-Feb-10 1:39 
GeneralRe: Button not firing in WPF Toolkit datagrid Pin
Member 454056418-Feb-10 10:10
Member 454056418-Feb-10 10:10 
QuestionSharing Core Objects Between Server & Client Pin
Jammer12-Feb-10 7:57
Jammer12-Feb-10 7:57 
AnswerRe: Sharing Core Objects Between Server & Client Pin
Pete O'Hanlon12-Feb-10 9:33
mvePete O'Hanlon12-Feb-10 9:33 
GeneralRe: Sharing Core Objects Between Server & Client Pin
Jammer13-Feb-10 12:51
Jammer13-Feb-10 12:51 
QuestionPopup window in silverlight Pin
xodeblack12-Feb-10 6:01
xodeblack12-Feb-10 6:01 
AnswerRe: Popup window in silverlight Pin
Abhinav S12-Feb-10 8:10
Abhinav S12-Feb-10 8:10 
Questioncontrols visible in designer but not available in window at runtime [modified] Pin
Member 290565112-Feb-10 2:30
Member 290565112-Feb-10 2:30 
QuestionButton click event within a ControlTemplate? Pin
Richard Dutton12-Feb-10 1:02
Richard Dutton12-Feb-10 1:02 
AnswerRe: Button click event within a ControlTemplate? Pin
rhuiden12-Feb-10 4:59
rhuiden12-Feb-10 4:59 
GeneralRe: Button click event within a ControlTemplate? Pin
Richard Dutton12-Feb-10 5:05
Richard Dutton12-Feb-10 5:05 
QuestionMessage Removed Pin
11-Feb-10 7:39
fjparisIII11-Feb-10 7:39 
AnswerRe: Initial impression: Silverlight much harder than WPF Pin
Not Active11-Feb-10 8:24
mentorNot Active11-Feb-10 8:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.