Did you make the application via the "WPF Application" template in Visual Studio 2008? If not try doing that then porting your source code over to the new app and see it it works. What does SetUiAsBusy() do?
Sincerely, -Ron
Did you make the application via the "WPF Application" template in Visual Studio 2008? If not try doing that then porting your source code over to the new app and see it it works. What does SetUiAsBusy() do?
Sincerely, -Ron
Yes the app class is the place to do the check. Try putting code inside the App:OnStartup() function. public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { bool mutexCreated; mutexRunOnce = new System.Threading.Mutex( true, "{someGUID}", out mutexCreated); if (!mutexCreated) { return; } base.OnStartup(e); } //... }
Sincerely, -Ron
Can you reproduce the problem in a very small, simple as possible app that reproduces the problem? Then post a complete set of snippets here such that others can use them to recreate an app to see the problem occur too.
Sincerely, -Ron
Please help. I tracked down a bug down to the fact that a toggle button in my app ignores it’s binding. I’ve simplified to the enclosed example WPF app. What I want is the BoundToChecked toggle button to only reflect the real value of ValueSource.Checked. What occurs is when the BoundToChecked toggle button is clicked it changes visual state even if ValueSource.AllowChange is false! Any suggestions or advice would be most appreciated. Thanks, Ron // ValueSource.cs using System; using System.ComponentModel; namespace ToggleButtonBound { class ValueSource : INotifyPropertyChanged { private bool _allowChange; public bool AllowChange { get { return _allowChange; } set { _allowChange = value; OnPropertyChanged("AllowChange"); } } private bool _checked; public bool Checked { get {return _checked;} set { if (AllowChange) { _checked = value; OnPropertyChanged("Checked"); } } } #region INotifyPropertyChanged Implementation public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string property) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(property)); } } #endregion } } // Window1.xaml <Window x:Class="ToggleButtonBound.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:me="clr-namespace:ToggleButtonBound" Title="ToggleButtonBound" Height="300" Width="300"> <Window.Resources> <me:ValueSource x:Key="ValueSource" /> </Window.Resources> <StackPanel> <ToggleButton Content="Unbound"/> <ToggleButton Content="BoundToChecked" IsChecked="{Binding Source={StaticResource ValueSource}, Path=Checked, Mode=Default}"/> <CheckBox Content="AllowChange" IsChecked="{Binding Source={StaticResource ValueSource}, Path=AllowChange, Mode=Default}"/> </StackPanel> </Window>
I'd like to have a globals class in my app with a global dictionary, but am having trouble getting past the error below. Any ideas or suggestions? using System; using System.Collections.Generic; namespace GlobalDict { public partial class Globals { public static Dictionary<string, int> GlobalInts = new Dictionary<string, int>() { {"one", 1}, {"two", 2}, }; } class Program { public static Globals g = new Globals(); static void Main(string[] args) { int i = g.GlobalInts["two"]; /* Error: Member 'GlobalDict.Globals.GlobalInts' * cannot be accessed with an instance reference; * qualify it with a type name instead */ } } }
Sincerely, -Ron
Thanks Pete. That did it. Upon reflection, the binding already included XPath so it did not need to be in the data template.
Sincerely, -Ron
Folks, I've been staring at this for hours and am missing something simple. Items in the first list box show up fine. However, I need to use a DataTemplate because the items in my real app are much more complex. Three items show up in the second listbox but they are all blank. Any ideas? <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Page1"> <Page.Resources> <XmlDataProvider x:Key="SetProvider" XPath="SetNums"> <x:XData> <SetNums xmlns=""> <SetNum>0</SetNum> <SetNum>1</SetNum> <SetNum>2</SetNum> </SetNums> </x:XData> </XmlDataProvider> <DataTemplate x:Key="SetTemplate"> <Label Content="{Binding XPath=SetNum}"/> </DataTemplate> </Page.Resources> <StackPanel Orientation="Horizontal"> <ListBox x:Name="lstWorks" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> <ListBox x:Name="lstDoesNotWorkWhyDoItemsAppearBlank" ItemTemplate="{StaticResource SetTemplate}" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> </StackPanel> </Page>
Sincerely, -Ron
Even for a message box?
Sincerely, -Ron
How can one apply an application style to the Common Dialogs? I've got a dark style going on in my app and this file open dialog is so bright it is jarring. Any ideas? // Configure open file dialog box Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = "Document"; // Default file name dlg.DefaultExt = ".txt"; // Default file extension dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension // Show open file dialog box Nullable<bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document string filename = dlg.FileName; }
Sincerely, -Ron
http://www.beacosta.com/blog/?p=11[^]
Sincerely, -Ron
http://en.wikipedia.org/wiki/Windows_Presentation_Foundation[^]
Sincerely, -Ron
Don't know but Bea Costa has a great blogspot that shows how to hide/show the expander: http://www.beacosta.com/blog/?cat=7[^] Perhaps there is a similar pattern for which you seek.
Sincerely, -Ron
I am trying to create an app with a progress bar styled from Blend's SimpleProgressBar such that Part_Indicator grows vertically toward the top of the screen as progress value increases. Problem is that Blend's SimpleProgressBar Part_Indicator dissapears when Orientation="Vertical"! The default Progress Bar works fine. Blend's SimpleProgressBar also works fine with Orientation="Horizontal". Comparing SimpleProgressBar to the default style for Progress bar revealed a control template trigger was missing from SimpleProgressBar for when Orientation="Vertical". I added it as follows but the PART_Indicator does not rotate. Are borders rotatable? It is probably something simple that is missing. <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="LackOfProgress.Window1" Title="Window1" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"> <Window.Resources> <LinearGradientBrush x:Key="PressedBrush" EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#BBB" Offset="0.0"/> <GradientStop Color="#EEE" Offset="0.1"/> <GradientStop Color="#EEE" Offset="0.9"/> <GradientStop Color="#FFF" Offset="1.0"/> </LinearGradientBrush> <SolidColorBrush x:Key="SolidBorderBrush" Color="#888"/> <LinearGradientBrush x:Key="NormalBorderBrush" EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#CCC" Offset="0.0"/> <GradientStop Color="#444" Offset="1.0"/> </LinearGradientBrush> <LinearGradientBrush x:Key="MouseOverBrush" EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#FFF" Offset="0.0"/> <GradientStop Color="#AAA" Offset="1.0"/> </LinearGradientBrush> <Style x:Key="SimpleProgessBar" TargetType="{x:Type ProgressBar}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ProgressBar}"> <Grid> <Border x:Name="PART_Track" Background="{DynamicResource PressedBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1" CornerRadius="2"/> <Border HorizontalAlignment="Left" x:Name="PART_Indicator" Background="{DynamicResource MouseOverBrush}" BorderBrush="{DynamicResource NormalBorderBrush}" BorderThickness
It was just a guess. There are quite a few options for that setting and it is not really clear how each one behaves. Probably experimenting with them is the only way to find out for sure. I can see your problem is complex. You might try an MFC forum as well. I'm fresh out of ideas. Good luck.
Sincerely, -Ron
Turns out I forgot to add StaticResource to the original xaml. Following works: <Window x:Class="Dependent.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Dependent" > <Window.Resources> <local:Peep x:Key="MyBestPeep" Name="Lisa" Number="5551212" /> </Window.Resources> <StackPanel> <TextBox Text="{Binding Source={StaticResource MyBestPeep}, Path=Name, Mode=Default}" /> <TextBox Text="{Binding Source={StaticResource MyBestPeep}, Path=Number, Mode=Default}"/> <Button Click="Button_Click">NewBestPeep</Button> </StackPanel> </Window>
using System; using System.Windows; using System.ComponentModel; namespace Dependent { public class Peep : INotifyPropertyChanged { public Peep() {} public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } private string name; public string Name { get { return name; } set { name = value; NotifyPropertyChanged("Name");} } private Int32 number; public Int32 Number { get { return number; } set { number = value; NotifyPropertyChanged("Number");} } } public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { Peep mybestpeep = TryFindResource("MyBestPeep") as Peep; mybestpeep.Name = "Denis"; mybestpeep.Number = 5551234; mybestpeep.Name = "Bragi"; mybestpeep.Number = 5554321; } } }
Sincerely, -Ron
Thanks Karl. I tried the following to no avail... namespace Dependent { public class Peep : INotifyPropertyChanged { public Peep() { } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } private string name; public string Name { get { return name; } set { name = value; NotifyPropertyChanged("Name"); } } private Int32 number; public Int32 Number { get { return number; } set { number = value; NotifyPropertyChanged("Number"); } } } }
The following appears in the output window on run: System.Windows.Data Error: 35 : BindingExpression path error: 'Name' property not found on 'object' ''String' (HashCode=-1333902949)'. BindingExpression:Path=Name; DataItem='String' (HashCode=-1333902949); target element is 'TextBox' (Name='txtName'); target property is 'Text' (type 'String') System.Windows.Data Error: 35 : BindingExpression path error: 'Number' property not found on 'object' ''String' (HashCode=-1333902949)'. BindingExpression:Path=Number; DataItem='String' (HashCode=-1333902949); target element is 'TextBox' (Name='txtNumber'); target property is 'Text' (type 'String')
Sincerely, -Ron
Have you tried KeyboardNavigation.TabNavigation="None" for your user control ?
Sincerely, -Ron
The text boxes come up blank in the following app and I would like them to show the name and number of my favorite peep. Any ideas? namespace Dependent { public class Peep { public Peep() { } private string name; public string Name { get { return name;} set { name = value;} } private Int32 number; public Int32 Number { get { return number;} set { number = value;} } } }
<Window x:Class="Dependent.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Dependent" > <Window.Resources> <local:Peep x:Key="MyBestPeep" Name="Lisa" Number="5551212" /> </Window.Resources> <StackPanel> <TextBox x:Name="txtName" Text="{Binding Source=MyBestPeep, Path=Name, Mode=Default}"/> <TextBox x:Name="txtNumber" Text="{Binding Source=MyBestPeep, Path=Number, Mode=Default}"/> </StackPanel> </Window>
Sincerely, -Ron
Try <ListBox SelectionMode="Multiple" KeyboardNavigation.DirectionalNavigation="Cycle">
Sincerely, -Ron