Click here to Skip to main content
15,171,053 members

Comments by Leung Yat Chun (Top 18 by date)

Leung Yat Chun 29-May-14 12:14pm View
Hello kartikguha,

Your code is binding to the DataContext of parent TabItem property, not the TabItem.
I think if you want to bind to the dependency property, you have to use Trigger instead of DataTrigger, e.g.

Joseph Leung
Leung Yat Chun 22-May-14 5:20am View
I think Fahad is using Modern UI on CodePlex.
Leung Yat Chun 5-Jan-14 3:32am View
You can also setup a binding to the text (Low,Medium,High) and add a trigger in the style of ListViewItem...instead of color.
Replace Trigger with DataTrigger to bind to the ViewModel.

<Style TargetType="ListViewItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Trigger Property="Content" Value="Low">
<Setter Property="Foreground" Value="Green" />
<Trigger Property="Content" Value="Medium">
<Setter Property="Foreground" Value="Blue" />
<Trigger Property="Content" Value="High">
<Setter Property="Foreground" Value="Red" />

Leung Yat Chun 22-Dec-13 14:18pm View
I don't know how to do it without using xaml, but I think you can inherited from ContentControl instead.
public class Control1 : ContentControl
{ public override void OnApplyTemplate() { base.OnApplyTemplate(); Content = new Grid(); } }
Leung Yat Chun 5-Dec-13 2:27am View
Or better yet, use MouseButtonEventArgs.ClickCount.
Leung Yat Chun 5-Dec-13 2:12am View
Did you set SelectedIndex?
Leung Yat Chun 27-Nov-13 3:17am View
Whats your implementation in VinylViewModel.Updater.Execute?
It's supposed to call InsertVinyl(), but nothing is there.
Leung Yat Chun 26-Nov-13 10:46am View
Canvas do not automatically resize itself when you add items to it, while I searching for solution around I found this: (take a look to the CanvasAutoSize)
Leung Yat Chun 26-Nov-13 9:58am View
Hello, you can bind child's ItemContainerStyle to parent's ItemContainerStyle.

If you need different style for different TreeViewItem (e.g. alternate background color), you have to use ItemContainerStyleSelector instead of ItemContainerStyle.
Leung Yat Chun 23-Nov-13 0:38am View
e.g. this one, you just have to change the code in settings to update the UI.
Leung Yat Chun 23-Nov-13 0:23am View
Your ScrollViewer is not activated, because your Canvas doesn't fill the Grid.

<scrollviewer name="QpRulesScrollViewer" height="150" width="100" verticalscrollbarvisibility="Visible" cancontentscroll="True">
<Canvas Name="QPRulesCanvas" Height="300">


You have to expand your canvas manually, so a easier solution is to write a Panel that expand when needed, to replace the canvas.
Leung Yat Chun 17-Nov-13 4:22am View
Hello, this is for WPF only, I don't know how to hook it to WinForms.

<Slider DockPanel.Dock="Bottom" Height="20" Minimum="0" Maximum="3600" x:Name="slider" />
<TextBlock Text="Z" FontSize="50" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center">
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="{Binding Value, ElementName=slider}" />

It uses LayoutTransform, in some case you can should use RenderTransform. As the name suggested LayoutTransform update it's layout in it's parent container as well, which means if you have a ScaleTransForm (change size of your control) with ScaleX and ScaleY set to 20, the panel grow because of that. RenderTransform doesn't update the layout. If you search LayoutTransform vs RenderTransform, you can find some useful articles.
Leung Yat Chun 12-Nov-13 10:46am View
Yes, try it and see if it works.
Leung Yat Chun 12-Nov-13 1:12am View
Lets say you have a list view named lview, e.g. in mark up <ListView x:Name="lview" />, in your main window, you can call
lview.AddHandler(ListView.MouseMoveEvent, (MouseEventHandler)((o, e) => { );
Noticed that this uses MouseEventHandler, which means e is MouseEventArgs, because MouseMoveEvent return MouseEventArgs.
In the case of DragEventArgs, it's DragEnterEvent or DragLeaveEvent, you have to use DragEventHandler instead, so you need:
lview.AddHandler(ListViewItem.DragEnterEvent, (DragEventHandler)((o,e) => { /* e is DragEventArgs */ }));
DragEnter event trigger when dragged something on another item, it may not be suitable for your case.
Leung Yat Chun 11-Nov-13 13:22pm View
Hello, although you can obtain the ListViewItem via source property, you can use this method in UITools to retrieve the item using a Point:

/// Take a container (e.g. listbox) and a position and return the item (e.g. listboxItem) at that spot.

/// <param name="container"></param>
/// <param name="position"></param>
/// <returns>
public static I GetItemByPosition<i, c="">(C container, Point position)
where C : UIElement
where I : UIElement
DependencyObject obj = null;
(o) =>
if (UITools.FindAncestor(o) != null)
return HitTestFilterBehavior.Continue;
else return HitTestFilterBehavior.ContinueSkipSelf;
(r) =>
obj = r.VisualHit;
return HitTestResultBehavior.Stop;
new PointHitTestParameters(position));
//if (r == null) return null;

//DependencyObject obj = r.VisualHit;
while (!(obj is C) && (obj != null))
obj = VisualTreeHelper.GetParent(obj);

if (obj is I)
return obj as I;

return null;

And call it using this method:
lview.AddHandler(ListView.MouseMoveEvent, (MouseEventHandler)((o, e) =>
Debug .WriteLine(
UITools.GetItemByPosition<ListViewItem, ListView>(lview, e.GetPosition(lview)));
Leung Yat Chun 9-Nov-13 18:54pm View
In RoutedEventHandler, there are three properties can be used:
Sender (object that event handler attached to), OriginalSource (object that trigger up event) and Source (object that raise event) property.

You don't need to figure out the selected item by hit testing in this case, but if you want to do hit testing, you can try my UITools.cs
Leung Yat Chun 8-Nov-13 9:56am View
I think you may have to create a custom Panel, like this one :
Leung Yat Chun 7-Nov-13 2:54am View
no problem, other members may have a better solution.