wpf

The Background Property Problem in WPF

WPF Controls are divided into various baskets. Some controls belong to System.Windows.Controls namespace and other belong to Panel and other stuff. I am interested in getting the control as a Panel or Control type so I can change the Background property. The following code is not working: var element = ((sender as Panel) ?? (sender as ...

Preventing WPF TreeView's SelectedItemChanged event from bubbling

I have a WPF TreeView which triggers a SelectedItemChanged event. Whenever I select an item in the TreeView, the SelectedItemChanged event is triggered for the selected item and all of the selected node's ancestors in the tree. How do I prevent the SelectedItemChanged event from firing more than once? ...

Convert System.Drawing.Icon to System.Media.ImageSource

I've got an IntPtr marshaled across an unmanaged/managed boundary that corresponds to an Icon Handle. Converting it to an Icon is trivial via the FromHandle() method, and this was satisfactory until recently. Basically, I've got enough thread weirdness going on now that the MTA/STA dance I've been playing to keep a hosted WinForm from ...

WPF Databinding: How do I access the "parent" data context?

I have a list (see below) contained in a window. The window's data context has two properties, Items & AllowItemCommand. How do I get the binding for the Hyperlink's Command property needs to resolve against the window's DataContext? <ListView ItemsSource="{Binding Items}"> <ListView.View> <GridView> <GridViewCol...

WPF Firing the RoutedEvents with a Delay

I am gathering all the routed events fired for the MouseRightDownButton and storing them in a Queue. I have the Sender object as well as the RoutedEventArgs. Now, I need to fire those events one by one and with a little pause. I also want to update the UI as I fire each event. Do this require the Timer class? ...

WPF DataTemplate and Binding

I continue my understanding of MVVC with the code of MSDN and I have a question. In the .xaml they have a list of commands displayed to the screen. <Border Grid.Column="0" Style="{StaticResource MainBorderStyle}" Width="170" > <HeaderedContentControl Content="{Binding Path=Commands}" ContentTemplate...

WPF - Prism, Using EventAggregator in ServiceLayers and below

I'd like use the EventAggregator in my servicelayer and below. It is a desktop app, but we do not have PresentationCore or PresentationFramework in the servicelayer assemblies. I haven't actually used any of Prism yet, but the EventAggregator looks like something that has use beyond the presentation layer. Just looking at the source, ...

Streaming audio file to another computer

Hello everybody, This is what I am trying to do. We are 5 people in a room. Everybody has a PC. Each PC has mp3 files but only one of the PCs has speakers (ex. called Speakers-PC). So, instead of asking the person on Speakers-PC to play you a song you want, I was thinking of an application that can take an audio file from a No-Speakers-...

How does Prism compare with Caliburn?

Looking at the Prism and Caliburn frameworks as a WPF newbie, what are their relative strengths and weaknesses? ...

WPF styling tabitem text foreground upon trigger such as IsEnabled, IsMouseOver, etc.

I'm trying to change the foreground text colour of a WPF tab item's header textblock using triggers. This works fine for most (simpler) scenarios but not when TextBlocks have been globally styled. So this simple "mouse over" trigger would work in terms of changing the foreground color: <Style x:Key="testTabItemStyle1" TargetType="{x:Ty...

Why can't WPF bind to UserControl properties?

public class Meh : DependencyObject { public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(string), typeof(Meh)); public string MyProperty { get { return (string)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value); } } } Now...

WPF Path vs Image png jpg..

Consider a Button composed of many graphical elements (and Path) drawn on Canvas. Why is it better to use the Path and other elements to build an image in that Button than assigning a custom Bitmap to it? I know one advantage, "the path is a vector image". But if I'm not planning to zoom, why should I use it in place of my custom .png,...

How to define a global custom RoutedCommand?

Hi, I would like to use the same custom RoutedCommand for 2 buttons, which are in separate windows. In order to not repeat the code, i want to define the command somewhere in the app and bind it to both buttons. I thought of using Style to achieve that. Below, I reproduce my issue in a simple sample. I declare the Style in App.Xaml :...

Announcments Control in WPF

What is the recommended way to implement an announcments (or news) control in WPF? Thanks. ...

SetParent COM and WPF

Hello there! I have two screens. one created in vb and the second is in WPF. I must embed the vb inside the wpf. Therefore i had an idea to firstly create a new Windows Form's form, and to use win32 API function "SetParent" in order to embed the vb screen inside the windows form. Secondly, host the winform inside the wpf form using ...

WPF/C#: Disable Drag & Drop for TextBoxes?

Hello, Does anyone have an idea how I can disable Drag & Drop for all my TextBox Elements? I found something here , but that would need me to run a loop for all Elements.. Thank you! EDIT Thanks a lot for the help! ...

WPF ControlTemplate vs UserControl

Hi. I've recently made an UserControl, which took quite a long time, because I had to work with custom Dependency Properties and so on... Anyways, it was just a bunch of 3 controls: TextBox, Popup with Hierarchical Tree. Now I realized I could probably write a ControlTemplate only. Hence what is the benefit of using UserControl? ...

How can I make WPF Trigger for IsMouseOver on TreeViewItem NOT affect all parents of the moused-over control?

I understand why this is happening. The bounding box of a parent TreeViewItem includes its children's bounding boxes, so when I am moused over a TreeViewItem, all its parents in the tree are also moused over. Is there something besides IsMouseOver I should be using? ...

WPF TemplateBinding vs RelativeSource TemplatedParent

What is the difference between <ControlTemplate TargetType="{x:Type Button}" x:Key="buttonTemplate"> <Border BorderBrush="{TemplateBinding Property=Background}" BorderThickness="3" > <ContentPresenter Margin="10"/> </Border> </ControlTemplate> and <ControlTemplate TargetType="{x:Type Button}" x:Key="buttonTemplate"> ...

how to establish connection to database using WPF, C# and XAML

Hi All, I started developing simple application in WPF and XAML. I want to try accessign the sql server database and display the data from stored procedure onto the UI form. I have a table called parentProject -> idParentProject (pk), txtParentProjName varchar(max). my SP is parentProj_sp -> select * from parentProject. n I want to us...