|
|
I think I posted the wrong snippet for the first attempt. I used FindResource there.
No matter which way I tried it, the CellTemplate showed that it was set, but the column did not reflect the settings I was trying to set.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I found the problem. This is the code that was creating the GridViewColumn:
DataTemplate cellTemplate =
Binding binding = new Binding()...
GridViewColumn column = new GridViewColumn()
{
Header = "...",
DisplayMemberBinding = binding,
CellTemplate = cellTemplate,
};
I had to change it to NOT set the DisplayMemberBinding property:
GridViewColumn column = new GridViewColumn()
{
Header = "...",
DisplayMemberBinding = (celltable == null) ? binding : null,
CellTemplate = cellTemplate,
};
And now it does exactly what I want it to do.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Glad it's working.
Might be a timing thing:
Quote: Resources can also be referenced by code from within the collection, but be aware that resources created in XAML will definitely not be accessible until after Loaded is raised by the element that declares the dictionary.
(I see now you're "creating" on the fly; I was "switching" when I looked back at my app).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
It's a binding thing - I was using DisplayMemberBinding, and then trying to apply a template that did its own binding - you can't do both, and when you try, it always does the DisplayMemberBinding first.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
That makes sense.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I have an icon (resource, do not copy) in my project.
I added an Image element to my xaml.
<Image Source="pack://application,,,/Pilot128.ico" Height="24" />
The icon shows up in the designer, but not when I actually run the app.
However, when I do this, it works as expected:
<Window.Resources>
<BitmapImage x:Key="appIcon" UriSource="Pilot128.ico" />
</Window.Resources>
<Image Source="{StaticResource appIcon}" Height="24" />
Why doesn't the first way work?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Have you tried either:
<Image Source="/Pilot128.ico" Height="24" /> or:
<Image Source="pack://application:,,,/YourAssemblyName;component/Pilot128.ico" Height="24" /> The documentation[^] seems to suggest that your URI should work, but I don't think I've ever managed to make it work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yeah, they both do the same thing.
I guess I'm fine with what I have to do to get this to work, but it doesn't make any sense that I *have* to do that way, unless it's because it's an ICO file as opposed to a png/jpg?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
|
When does the next tick start. Watching how things seem to preform it seems like:
Tick
Execute Tick routine, pause tick timer
Tick routine ends, restart tick timer
It seems like the tick interval is between the tick routines. It is OK, I just want to make sure I understand it correctly.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
You have the sequence wrong!
Tick
Stop the timer
process the tick routine
restart the timer.
If your process is longer than the timer interval it clags up the system.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
That's what I meant. Maybe I did not state it well.
"it clags up the system" is what I thought at first but it seems to follow the above sequence fairly well. As I change the tick interval it seems to be offset by a constant. My tick routine has to read some USB analog inputs. It is slow but consistent.
I cannot find anything on the web to explain clags.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
Sorry - slang
You end up with queued processes that are re-launched before the last one is completed therefore you need to insure that only 1 process is launched at a time.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I like the slang better.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
You only need to pause, if the tick event takes longer to execute than the interval if you want a "proper" timer.
And if you're re-entrant, you don't need to pause either.
Pausing implies your interval is "off".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
In my current way to structure a WPF-application I heavily lean on UserControls for my Views and place them in the MainWindow inside a container, usually a DockPanel. For instance in the MainWindow:
<DockPanel LastChildFill="True">
<views:Header DockPanel.Dock="Top" />
<views:Footer DockPanel.Dock="Bottom" />
<views:Body />
</DockPanel> For each View I have a corresponding ViewModel. This ViewModel is instantiated inside the View's XAMl-code. In the DataContext element. For instance in the Body View:
<UserControl.DataContext>
<vm:BodyViewModel />
</UserControl.DataContext> I like this approach, because I can alter any properties in the ViewModel and see the View automatically change in the view during design time.
But I have not find a good way to access any ViewModels from some class where I happened to need to alter the View through a property in a ViewModel.
My current solution - which I don't like - to gain access of the ViewModels is:
1. Give each View a name in the MainWindow.xaml file.
<DockPanel LastChildFill="True">
<views:Header DockPanel.Dock="Top" x:Name="viewHeader" />
<views:Footer DockPanel.Dock="Bottom" x:Name="viewFooter" />
<views:Body x:Name="viewBody" />
</DockPanel> 2. Do some logic in the MainWindow to setup the ViewModels for each View.
public partial class MainWindow : Window
{
HeaderViewModel Header { get; set; }
FooterViewModel Footer { get; set; }
BodyViewModel Body { get; set; }
public MainWindow()
{
InitializeComponent();
Header = viewHeader.DataContext as HeaderViewModel;
Footer = viewFooter.DataContext as FooterViewModel;
Body = viewBody.DataContext as BodyViewModel;
}
} 3. Then for every class where I need a ViewModel I need to pass it from the MainWindow in some way.
class SomeClass
{
public void AlterHeaderText(HeaderViewModel header)
{
}
} This approach works, but I don't like it. It's annoying to pass ViewModels from the MainWindow every time a class need one or more ViewModels to alter a View.
Is there a solution to this approach to improve it?
/BR
Steffe
|
|
|
|
|
You're accessing the UC's directly: tight coupling.
Ideally, you should be communicating only with the Main Window; using methods / an interface that works indirectly with the UC's; e.g. "set heading title".
Use a static (e.g. .Current) to access "main window" and any other windows / UC's that only exist as singletons (at any given time).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
If you have a viewmodel for each user control, why is the setup performed in the main window anything more than adding the user control to the parent content control (a grid?)? The view should do all of its own setup, and should betotally self-contained at that point. Sure, you may have some sort of global data, but in the end, the user control and its viewmodel should really be completely self-contained, and the main window shouldn't even be involved.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Look at MVVM Light or its soom to be replacement Microsoft.Toolkit.MVVM. They have there place but personally I think they can make simple things more complicated.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
Historically (and in my experience), Microsoft's "convenience" frameworks are too generic to be even remotely useful. And the closer you get to an enterprise-sized application, the worse it gets.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
You could use singletons. I posted an article that uses singletons for app settings, the connection string for a database, and the DAL object I use to access the database. If you look at the source code, you'll see how to do it (or at least, how I did it).
Entity Factory - Get Your ORM-less Freak On![^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Alright, I'm at a loss. I'm trying to get a TextBox to display WPF's default red border around the control. I know for a fact that the error condition is being detected, but the border color isn't changing. I think I'm just bench blind, but I've been playing with this for two days now with no success. Can anyone see/think of anything I'm doing wrong?
0) I've implemented IDataErrorInfo on my control (which already inherits INotifyPropertyChanged ):
public partial class WizPgQuery : WizardPageBase, IDataErrorInfo
{
public string this[string columnName]
{
get
{
string value;
switch (columnName)
{
case "ClassName": value = this.ValidateClassName(); break;
case "QueryText": value = this.ValidateQueryText(); break;
default : value = string.Empty; break;
}
return value;
}
}
public string Error
{
get { throw new NotImplementedException(); }
}
1) I have my property and validation routines implemented
private string className;
public string ClassName
{
get { return this.className; }
set
{
if (value != this.className)
{
this.className = value;
this.NotifyPropertyChanged();
}
}
}
private string ValidateClassName()
{
string value = (this.ClassName.IsValidClassName())
? ""
: "The class name must be a valid C# identifier.";
if (!string.IsNullOrEmpty(value)) { SystemSounds.Beep.Play(); }
return value;
}
2) My XAML looks like this:
<TextBox x:Name="textboxClassName" Grid.Column="1"
Text="{Binding Path=ClassName,
Mode=TwoWay,
ValidatesOnDataErrors=True,
ValidatesOnExceptions=True,
NotifyOnValidationError=True,
UdateSourceTrigger=PropertyChanged}"
TextChanged="TextboxClassName_TextChanged"
ToolTip="Base tool tip" />
3) No dynamic/static resources defined that might override WPF's default presentation behavior
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
|
That's for setting the tooltip (on error). I just want the border to turn red (which is supposed to be the default behavior).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|