wpf

Why the need to create observable collection

i am watching this tutorial. at around 15:40, the speaker said something like a LINQ query won't create a rich collection like BindingListCollectionView. i am thinking maybe it means changes wont be saved to the database or something. so i tried replacing var result = database.Customers.Execute(System.Data.Objects.MergeOption.AppendOnly...

Binding DayOfWeek enum to Custom Calendar Control Grid

For a very custom calendar control, I need to have a week object and bind the Day objects within that week to a grid. I figured I would have the DayOfWeek enum decide where the day should go within the grid. That way if the month starts on a Tuesday it'll have the property Grid.Column="2". But for some reason all of them end up in the...

How to debug this error when none of my code shows up in the stack ?

I'm sometimes getting the following error in my application: Cannot use a DependencyObject that belongs to a different thread than its parent Freezable I know how to solve this kind of error, but in that case I have no idea where it is happening, so I don't know what to fix... The exception's stack trace only contains .NET framewor...

How to know when to call base method or override methods in observable collection

i have some questions when watching this tutorial. i wonder when i overwrite methods, how do i know if i need to call the base method? public CustomerCollection(IEnumerable<Customer> customers, OMSEntities context) : base(customers) also why do i need to do protected override void InsertItem(int index, Customer cust) { this.co...

Having trouble binding the Visibility of a ContentPresenter in WPF

I have the following XAML: <UserControl.Resources> <DataTemplate x:Key="ExpanderTemplate"> <Grid> <Rectangle Stroke="Black" StrokeThickness="1" Width="10" Height="10" Fill="White" /> <Rectangle Stroke="Black" StrokeThickness="1" Width="6" Height="1" Fill="Black" /> <Rectangle Stroke="Black" StrokeThickness="...

What event should I monitor for a timely task in WPF?

I am writing a WPF application using C#. I need the application to continue to run for two minutes and then perform some maintenance. The user may not be interacting with it so user driven events are not guaranteed. What is the event I should be monitoring to fulfill this requirement? Here is some pseudo code of what I am considering...

Best practices for moving objects to a separate thread

We have an implementation for an Ultrasound machine application current where the Ultrasound object is created on the UI's thread. A Singleton implementation would have been good here, but regardless, isn't. Recently, the set methods changed such that they automatically stop and restart the ultrasound machine, which can take between 10-...

Different Xp styles are changing my control apperances, how do I avoid it?

I thought everything was looking good with my user controls, styles and layout etc, until I released a version for the user to test. They asked if the Toggle button could be Green when checked. I said it is, but it wasn't. I checked on my machine and it was Green. Turns out he has a different xp style set to me. i.e. he has 'Windows...

Cannot manipulate panel after RenderTargetBitmap.

Hi, I've found a perfect storm of conditions that create a situation where my panel is no longer updating properly. Here is the concept: I have a grid with a viewbox displaying a canvas with lines in radiating patterns. When I attempt to render the entire grid to bitmap, the bitmap looks fine. However, at this point forward, if I ch...

How can I define a ControlTemplate for my TabControl without breaking automated testing?

Summary In my WPF application, I needed a TabControl with buttons on the left, so I defined a ControlTemplate with the layout I wanted and it worked fine. However, my tester's automated testing tool can't see any of the content of the tabs, including the currently selected tab. Question: How can I keep my TabControl testable by the au...

How can I read/write app.config settings at runtime without using user settings?

I'm looking for a way to store application or machine level settings that can be written to at runtime using Application Settings. User settings allow read/write but application settings do not. I have been using user settings for saving settings like this at runtime but this has really proven to be impractical for the following reasons:...

WPF TextBox: error setting style

Hi, I have defined style for my textboxes that would show hints about what to enter when the textbox is empty. This would be my window: <Grid> <Grid.Resources> <Style TargetType="{x:Type TextBox}" x:Key="stlHintbox"> <Style.Triggers> <DataTrigger Binding="{Binding Text, RelativeSource={RelativeS...

RibbonComboBox MouseLeave Event doesnt fire

I cant get mouseleave to fire inside a ribboncombobox inside a ribboncontrolgroup inside ribbon tab inside a ribbon. I have a behavior that on mouse enter opens the dropdown and should close it on mouseleave except mouseleave doesnt fire I verified this using snoop and by setting a breakpoint on the event. Any ideas or workarounds? ...

WPF Bind to parent property from within nested element using style

Hi, I've been trying to build a text box with a hint that's displaying while it's empty. I'm having trouble setting the hint text from within a style. To be precise, this works (that is, it binds correctly): <TextBox Tag="hint text"> <TextBox.Background> <VisualBrush Stretch="None"> <VisualBrus...

How to set selected value path to tab header text in a tab control in WPF.

The title really says it all here. I am a little unclear on how I would set the SelectedValuePath of a TabControl to the text of the selected TabItems header. I feel like this should be fairly simple, and probably involves content.something but I have always been a bit confused about the Content property. Thanks ...

WPF/C#: Creating a button style: Text + Image

I just want to ask how should I put my image (dynamically) in this following code: <Style x:Key="ButtonStyler" TargetType="{x:Type Button}"> <Setter Property="Background"> <Setter.Value> <RadialGradientBrush> <RadialGradientBrush.GradientStops> <GradientStopCollection> ...

Detecting when a tab item was added to WPF Tab control

I am trying to synchronize the selected tab item of a WPF tab control with the last item that was added. Since there is no such property as e.g. IsSynchedWithLastAddedItem, I am trying to detect when an item was added in order to point the SelectedItem at the last added one. I cannot find the event that gets raised - either on the tab ...

WPF Text overflow

I'm currently trying to make it so that when I take a string, it fills up the first textblock until it overflows and then it should start in textblock 2. Currently, I have it to where the string is cut into two pieces at the last end of the last word before it hits what I guess to be the max characters that can fit into textblock one, an...

How do I log an exception when I don't know where it might throw?

We have a WPF application that we've deployed to the customer. However, the application is randomly fatally crashing with an "unexpected error" dialog box on the customer's computer. We need to be able to see the exception message and preferably stack trace as well, but because it's crashing randomly, we don't know where we should be put...

INotifyPropertyChanged: what happens behind the scene?

In WPF we have two threads (at least): rendering and a UI thread. When I raise an event OnNotifyPropertyChanged on some property changes, it is raised on the UI thread. This information needs to be dispatched to WPF rendering thread for re-rendering. I am assuming it is done in a synchronous manner ( Dispatcher.Invoke ) but how does it r...