Click here to Skip to main content
15,072,945 members

Comments by Leung Yat Chun (Fainx) (Top 18 by date)

Leung Yat Chun (Fainx) 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.
http://msdn.microsoft.com/en-us/library/ms743015%28v=vs.110%29.aspx

Regards
Joseph Leung
Leung Yat Chun (Fainx) 22-May-14 5:20am View
   
I think Fahad is using Modern UI on CodePlex.
Leung Yat Chun (Fainx) 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.

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

<ListViewItem>Low</ListViewItem>
<ListViewItem>Medium</ListViewItem>
<ListViewItem>High</ListViewItem>
</ListView>
Leung Yat Chun (Fainx) 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 (Fainx) 5-Dec-13 2:27am View
   
Or better yet, use MouseButtonEventArgs.ClickCount.
Leung Yat Chun (Fainx) 5-Dec-13 2:12am View
   
Did you set SelectedIndex?
Leung Yat Chun (Fainx) 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 (Fainx) 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:
http://stackoverflow.com/questions/855334/wpf-how-to-make-canvas-auto-resize (take a look to the CanvasAutoSize)
Leung Yat Chun (Fainx) 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 (Fainx) 23-Nov-13 0:38am View
   
e.g. this one, you just have to change the code in settings to update the UI.
http://stackoverflow.com/questions/845030/bind-to-a-value-defined-in-the-settings
Leung Yat Chun (Fainx) 23-Nov-13 0:23am View
   
Your ScrollViewer is not activated, because your Canvas doesn't fill the Grid.

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

</Canvas>
</scrollviewer>

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 (Fainx) 17-Nov-13 4:22am View
   
Hello, this is for WPF only, I don't know how to hook it to WinForms.

<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel>
<Slider DockPanel.Dock="Bottom" Height="20" Minimum="0" Maximum="3600" x:Name="slider" />
<TextBlock Text="Z" FontSize="50" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center">
<TextBlock.LayoutTransform>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="{Binding Value, ElementName=slider}" />
</TextBlock.LayoutTransform>
</TextBlock>
</DockPanel>
</Page>

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 (Fainx) 12-Nov-13 10:46am View
   
Yes, try it and see if it works.
Leung Yat Chun (Fainx) 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 (Fainx) 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;
//Bug#66
VisualTreeHelper.HitTest(
container,
(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 (Fainx) 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
http://fileexplorer.codeplex.com/SourceControl/latest#src/FileExplorer3/app/FileExplorer3/UserControls/UITools.cs
Leung Yat Chun (Fainx) 8-Nov-13 9:56am View
   
I think you may have to create a custom Panel, like this one : http://www.codeproject.com/Articles/37348/Creating-Custom-Panels-In-WPF.
Leung Yat Chun (Fainx) 7-Nov-13 2:54am View
   
no problem, other members may have a better solution.