Skip to content

Commit

Permalink
Issue #37 sample
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Aug 24, 2016
1 parent 52f2c01 commit 3efdfad
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 8 deletions.
43 changes: 43 additions & 0 deletions src/Showcase.WPF.DragDrop.NET45/Models/ItemModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;

namespace Showcase.WPF.DragDrop.Models
{
public class ItemModel : INotifyPropertyChanged
{
private double _bindableDoubleValue;

public ItemModel(int itemIndex)
{
this.Caption = $"Item {itemIndex}";
this.BindableDoubleValue = Faker.RandomNumber.Next(0, 100);
}

public string Caption { get; set; }

public double BindableDoubleValue
{
get { return _bindableDoubleValue; }
set
{
if (value.Equals(_bindableDoubleValue)) return;
_bindableDoubleValue = value;
OnPropertyChanged();
}
}

public override string ToString()
{
return this.Caption;
}

public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
21 changes: 13 additions & 8 deletions src/Showcase.WPF.DragDrop.NET45/Models/SampleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public SampleData()
{
for (var n = 0; n < 50; ++n)
{
this.Collection1.Add($"Item {(n + 1)}");
this.Collection1.Add(new ItemModel(n + 1));
this.DataGridCollection1.Add(new DataGridRowModel());
}

Expand Down Expand Up @@ -41,20 +41,25 @@ public SampleData()
this.TabItemCollection2.Add(new TabItemModel(1));
}

public ObservableCollection<string> Collection1 { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> Collection2 { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> Collection3 { get; set; } = new ObservableCollection<string>();
public ObservableCollection<ItemModel> Collection1 { get; set; } = new ObservableCollection<ItemModel>();
public ObservableCollection<ItemModel> Collection2 { get; set; } = new ObservableCollection<ItemModel>();

public ObservableCollection<TreeNode> TreeCollection1 { get; set; } = new ObservableCollection<TreeNode>();
public ObservableCollection<TreeNode> TreeCollection2 { get; set; } = new ObservableCollection<TreeNode>();

public GroupedDropHandler GroupedDropHandler { get; set; } = new GroupedDropHandler();
public ObservableCollection<GroupedItem> GroupedCollection { get; set; } = new ObservableCollection<GroupedItem>();

public ObservableCollection<DataGridRowModel> DataGridCollection1 { get; set; } = new ObservableCollection<DataGridRowModel>();
public ObservableCollection<DataGridRowModel> DataGridCollection2 { get; set; } = new ObservableCollection<DataGridRowModel>();
public ObservableCollection<DataGridRowModel> DataGridCollection1 { get; set; } =
new ObservableCollection<DataGridRowModel>();

public ObservableCollection<TabItemModel> TabItemCollection1 { get; set; } = new ObservableCollection<TabItemModel>();
public ObservableCollection<TabItemModel> TabItemCollection2 { get; set; } = new ObservableCollection<TabItemModel>();
public ObservableCollection<DataGridRowModel> DataGridCollection2 { get; set; } =
new ObservableCollection<DataGridRowModel>();

public ObservableCollection<TabItemModel> TabItemCollection1 { get; set; } =
new ObservableCollection<TabItemModel>();

public ObservableCollection<TabItemModel> TabItemCollection2 { get; set; } =
new ObservableCollection<TabItemModel>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="Models\DataGridRowModel.cs" />
<Compile Include="Models\GroupedDropHandler.cs" />
<Compile Include="Models\GroupedItem.cs" />
<Compile Include="Models\ItemModel.cs" />
<Compile Include="Models\SampleData.cs" />
<Compile Include="Models\TabItemModel.cs" />
<Compile Include="Models\TreeNode.cs" />
Expand Down
73 changes: 73 additions & 0 deletions src/Showcase.WPF.DragDrop.NET45/Views/Issues.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:local="clr-namespace:Showcase.WPF.DragDrop.Views"
xmlns:viewModels="clr-namespace:Showcase.WPF.DragDrop.ViewModels"
xmlns:dd="urn:gong-wpf-dragdrop"
xmlns:models="clr-namespace:Showcase.WPF.DragDrop.Models"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance viewModels:MainViewModel}"
d:DesignHeight="400" d:DesignWidth="600">
Expand Down Expand Up @@ -128,6 +129,78 @@
</DockPanel>
</TabItem>

<TabItem Header="#37">
<TabItem.Resources>
<DataTemplate x:Key="Issue37DataTemplate" DataType="{x:Type models:ItemModel}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Col01" />
<ColumnDefinition Width="Auto" SharedSizeGroup="Col02" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Margin="2"
Text="{Binding Path=Caption, Mode=OneWay}" />
<TextBox Grid.Column="1"
Margin="2"
MinWidth="60"
Text="{Binding Path=BindableDoubleValue, Mode=OneWay, StringFormat={}{0:n2} %}" />
<Slider Grid.Column="2"
Value="{Binding Path=BindableDoubleValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Minimum="0"
Maximum="100"
SmallChange="5"
LargeChange="10"
Margin="2" />
</Grid>
</DataTemplate>
</TabItem.Resources>
<DockPanel LastChildFill="True">
<Grid DockPanel.Dock="Top">
<TextBlock Text="Crash when using items deriving from ContentControl" Style="{StaticResource SampleHeaderTextBlockStyle}" />
<Button CommandParameter="37" ToolTip="Open #37 on Github" Style="{StaticResource GitHubIssueButtonStyle}" />
</Grid>
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<StackPanel>
<TextBlock Style="{StaticResource DefaultTextBlockStyle}"
Text="ListBox with ItemTemplate which contains other controls. This controls also gets the mouse input, so drag action should not be started." />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ListBox Grid.Column="0"
Grid.IsSharedSizeScope="True"
x:Name="LeftIssue37ListBox"
HorizontalContentAlignment="Stretch"
ItemTemplate="{StaticResource Issue37DataTemplate}"
ItemsSource="{Binding Data.Collection1}"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.UseDefaultDragAdorner="True" />
<ListBox Grid.Column="1"
ItemsSource="{Binding Data.Collection2}"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.UseDefaultDragAdorner="False" />
</Grid>

<TextBlock Style="{StaticResource DefaultTextBlockStyle}"
Text="Customization (for left ListBox)" />
<CheckBox Margin="10 5" Content="IsDragSource"
IsChecked="{Binding ElementName=LeftIssue37ListBox, Path=(dd:DragDrop.IsDragSource), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<CheckBox Margin="10 5" Content="IsDropTarget"
IsChecked="{Binding ElementName=LeftIssue37ListBox, Path=(dd:DragDrop.IsDropTarget), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<CheckBox Margin="10 5" Content="UseDefaultDragAdorner"
IsChecked="{Binding ElementName=LeftIssue37ListBox, Path=(dd:DragDrop.UseDefaultDragAdorner), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<CheckBox Margin="10 5" Content="UseDefaultEffectDataTemplate"
IsChecked="{Binding ElementName=LeftIssue37ListBox, Path=(dd:DragDrop.UseDefaultEffectDataTemplate), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</ScrollViewer>
</DockPanel>
</TabItem>

</TabControl>

</Grid>
Expand Down

0 comments on commit 3efdfad

Please sign in to comment.