wpf

How to get a top object (Window or Page) in WPF?

Within my custom WPF control I want to get a containing Window or Page. Window.GetWindow() method works fine when control is in a windowed app but when it's in the XBAP app in a browser it returns browser window instead of the page. Is there any other way to do this? ...

How to present a Collection of (View)Models in a ViewModel

Hi. I have a question regarding the MVVM design for C#/WPF. I've had a look at several demo applications, but they didn't really handle my problem. My application consists of objects that contain other objects. Much like in a parent - children relationship. My question now is: does the children attribute have to be a ViewModel and ...

WPF Grid scroll

I want to create two grids in the WPF Page. One grid need scrollbar or scroll viewer. Another grid is static.The grids are placed one by one in the page. How to create and set the scroll in first grid.? plz explain me. ...

Composite Guidance for WPF : MVVM vs MVP.

Hi, I am confused. Maybe you can help me :) I have been following the guidance of CAG and found the MVP pattern very natural to me. Suppose I have a UI-ready Model (for example : implements INotifyPropertyChanged), I use the presenter to bind this Model to a view (presenter knows an interface of the view), keeping my Code-Behind as sma...

WPF Data Binding to changing object

Hi, I have a user control which displays the currently logged in user's name. I have bound a TextBlock in the control to the UserId property of a User obejct in my application. The issue I have is that the User object my binding has as a source changes each time a new user logs in. I can think of a solution where I fire an event when ...

Reuse path object in XAML

Hi all, I have a Path (a star figure): <Path x:Name="NiceStar" StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 126.578613,11.297852 L 162.373535,83.825684 L 242.412598,95.456055 L 184.495605,151.911133 L 198.167480,231.626953 L 126.578613,193.990234 L 54.988770,231.626953 L 68.661621,151.911133 L 10.744629,95.45...

How to keep window on top of another window in a different thread?

I have a WinForms form (call it 'MyForm') that hosts some WPF UI (via ElementHost). I show this form on a separate thread from the main UI thread. I want 'MyForm' to remain on top of the main application window, so I am showing the form using the Show(IWin32Window) overload of the Show method, with the passed-in IWin32Window being the m...

File has been modified? Now to handle in WPF?

Hi, What's the best way to tell my application that the file has been modified and that it should ask the user for a filename? Is there a class for that or do I write that all that logic by hand? Thanks! ...

[WPF] ObservableCollection and ListBoxItem DataTemplate generation problem

Something strange is going on with ObservableCollection. I have the following code: private readonly ObservableCollection<DisplayVerse> _display; private readonly ListBox _box; private void TransferToDisplay() { double elementsHeight = 0; _display.Clear(); for (int i = 0; i < _source.Count; i++) { DisplayVerse verse = ...

How to pass information from one WPF UserControl to another WPF UserControl?

I've got a WPF application. On the left side there is a stackpanel full of buttons. On the right side there is an empty dockpanel. When user clicks a button, it loads the corresponding UserControl (View) into the dockpanel: private void btnGeneralClick(object sender, System.Windows.RoutedEventArgs e) { PanelMainContent.Children.C...

WPF: Binding to ComboBox SelectedItem

Hi all I have a UserControl with ComboBox that based on XML data: <Root> <Node Background="Yellow" Foreground="Cyan" Image="1.ico" Property="aaaa" Value="28" /> <Node Background="SlateBlue" Foreground="Black" Image="2.ico" Property="bbbb" Value="2.5" /> <Node Background="Teal" Foreground="Green" Image="3.ico" Property="cccc" Value="4.0...

Is it possible to change the background color of a disabled button in WPF?

I am trying to get the effect of "dimming out the whole window and all controls on it". The window and everything on it also needs to be disabled. The problem is that when button is disabled, it doesn't seem to let you change the Background color. Is there a way in WPF to change the background color of a button even though it is disa...

WPF - Bind image property to Image control

Suppose I have string Name and Image Photo as properties of a class in my DataContext. I need to bind them to controls is a DataTemplate. I thought this would work but it doesn't: <Image Source="{Binding Photo}"/> Why not? Should I my Photo have another type? (BitmapImage perhaps?) How can I bind an Image control to an Image proper...

Where is the WPF Numeric UpDown control?

Getting into the first serious WPF project. It seems like there are a lot of basic controls flat out missing. Specifically, I am looking for the Numeric UpDown control. Was there an out of band release that I missed? Really don't feel like writing my own control. I do not want to use the WindowsFormHost and plop a WinForm ctl on i...

Prevent double-click from double firing a command

Given that you have a control that fires a command: <Button Command="New"/> Is there a way to prevent the command from being fired twice if the user double clicks on the command? EDIT: What is significant in this case is that I am using the Commanding model in WPF. It appears that whenever the button is pressed, the command is execu...

WPF Memory Usage

Application: WPF Application consisting of a textbox on top and a listbox below Users type a string in the TextBox to find employees, and search results are displayed in the ListBox ListBox uses DataTemplates to display elements (shows employee name, department, phone and a thumbnail picture.) Implementation: At application startu...

Type of object created by ListCollectionView.AddNew

How does ListCollectionView.AddNew determine the type of object it creates, and how could one affect it? I have a hierarchy of a few types (Base, DerivedA, and DerivedB), and currently my WPF Toolkit DataGrid creates DerivedA objects (why, I don't know -- probably because almost all the data in the grid is of that type), but I'd like it...

How do you keep the WPF window sized to content with an Expander after resize

I've got a WPF window with SizeToContent="Height". This window contains an <Expander /> that displays a list of recent activity. What I'd like is when the expander is expanded the window grows in size proportionally. When hidden the window again resizes proportionally. If the window is resized the expander and it's contained list view sh...

WPF: Display a bool value as "Yes" / "No"

I have a bool value that I need to display as "Yes" or "No" in a TextBlock. I am trying to do this with a StringFormat, but my StringFormat is ignored and the TextBlock displays "True" or "False". <TextBlock Text="{Binding Path=MyBoolValue, StringFormat='{}{0:Yes;;No}'}" /> Is there something wrong with my syntax, or is this type of ...

WPF hide MenuItem on ContextMenu based on object property

I need to programatically show/hide a MenuItem, what would be the best way to do this? ...