|
---modified. Original problem with this is solved, but I got a new problem with the same xaml ---
Ok I just started in WPF so it might be very obvious.
I made a UserControl which contains also a ToggleButton, when that togglebutton is pressed I want to alter the background of the border control.
<UserControl x:Class="StoreDBViewer.MyTableControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid>
<Border x:Name="MyCtrlBorder" BorderThickness="1" BorderBrush="Gray" Background="Green">
<!-- Here a bunch of controls and stuff is added -->
<ToggleButton x:Name="btnToggle" Margin="5,5" Click="OnToggleColView">
Button text
</ToggleButton>
</Border>
</Grid>
<UserControl.Triggers>
<Trigger SourceName="btnToggle" Property="ToggleButton.IsChecked" Value="True">
<Setter TargetName="MyCtrlBorder" Property="Border.Background" Value="Blue" />
</Trigger>
</UserControl.Triggers>
</UserControl>
This compiles correctly, but as soon as I run the app an exception is thrown( the exception is not thrown if I comment out the Trigger part).
Does anyone know what might be wrong here?
Regards,
Davy
modified on Monday, June 30, 2008 8:55 AM
|
|
|
|
|
What is the error message of the exception (or the message of the InnerException, or the InnerException of the InnerException, or however many levels it takes to find something useful)? In cases like this, the error messages usually have a good pointer for where to start looking.
|
|
|
|
|
Thanks for the reply.
The message of the exception itself was pretty useless, but following the innerexceptions 3 levels up I came to this message:
Triggers collection members must be of type EventTrigger.
So doing some research on that I found that this kind of trigger only works in ControlTemplate,DataTemplates and Style... So I guess I have to reorder some stuff in the xaml file to fit the triggers somewhere in a style or so.
Regards,
Davy
|
|
|
|
|
OK, this is a small WPF application that I am working on.
While testing, no problem appeared. Even when using the exe that would be released to everyone.
Now, in one of the text boxes I had put UndoLimit=-1, to avoid the problems with the undo limit. This worked perfectly on my machine. But a user reported this:
Exception: System.Windows.Markup.XamlParseException
28/06/2008 14:01:28
Message: Cannot find DependencyProperty or PropertyInfo for property named 'UndoLimit'.
Property names are case sensitive. Error at object 'txtDNA' in markup file 'Origones;component/mainwindow.xaml'.
Source: PresentationFramework
STACK TRACE
Void ThrowException(System.String, System.Exception, Int32, Int32, System.Uri,
System.Windows.Markup.XamlObjectIds, System.Windows.Markup.XamlObjectIds, System.Type)
at System.Windows.Markup.XamlParseException.ThrowExce ption(String message,
Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri,
XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
[Note: Some newlines added]
[Snipped]
Strangely enough, simply removing the UndoLimit fixed it.
Another problem with the same application: One of the users reported that the "portrait" had a purple tint. That problem is in this screenshot.[^]
Now, viewing the same files on my computer, and apparently everybody else's resulted in the correct coloring.
Has anybody had any experience with these strange small inexplicable problems?
modified on Sunday, June 29, 2008 9:44 AM
|
|
|
|
|
Looking at the UndoLimit documentation it appears this was added in 3.0sp1 so it could be a versioning issue for that user. The WPF performance tool has an option to tint software rendering in purple, perhaps that debug option got enabled or some graphics driver is causing problems? Does the portrait have any BitmapEffects applied to it which would cause it to be rendered in software?
The image you posted didn't work for me but perhaps you could test with the option enabled and see if they match, the part about deleting the registry key might help that user.
http://msdn.microsoft.com/en-us/library/aa969767.aspx#perforator
|
|
|
|
|
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
<br />
<br />
using System;<br />
<br />
using System.ComponentModel;<br />
<br />
namespace ToggleButtonBound<br />
<br />
{<br />
<br />
class ValueSource : INotifyPropertyChanged<br />
<br />
{<br />
<br />
private bool _allowChange;<br />
<br />
public bool AllowChange<br />
<br />
{<br />
<br />
get { return _allowChange; }<br />
<br />
set<br />
<br />
{ <br />
<br />
_allowChange = value;<br />
<br />
OnPropertyChanged("AllowChange");<br />
<br />
}<br />
<br />
}<br />
<br />
private bool _checked;<br />
<br />
public bool Checked <br />
<br />
{ <br />
<br />
get {return _checked;}<br />
<br />
set<br />
<br />
{<br />
<br />
if (AllowChange)<br />
<br />
{<br />
<br />
_checked = value;<br />
<br />
OnPropertyChanged("Checked");<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
#region INotifyPropertyChanged Implementation<br />
<br />
public event PropertyChangedEventHandler PropertyChanged;<br />
<br />
protected virtual void OnPropertyChanged(string property)<br />
<br />
{<br />
<br />
if (PropertyChanged != null)<br />
<br />
{<br />
<br />
PropertyChanged(this, new PropertyChangedEventArgs(property));<br />
<br />
}<br />
<br />
}<br />
<br />
#endregion<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<Window x:Class="ToggleButtonBound.Window1"<br />
<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
<br />
xmlns:me="clr-namespace:ToggleButtonBound"<br />
<br />
Title="ToggleButtonBound" Height="300" Width="300"><br />
<br />
<Window.Resources><br />
<br />
<me:ValueSource x:Key="ValueSource" /><br />
<br />
</Window.Resources><br />
<br />
<StackPanel><br />
<br />
<ToggleButton Content="Unbound"/><br />
<br />
<ToggleButton Content="BoundToChecked" IsChecked="{Binding Source={StaticResource ValueSource}, Path=Checked, Mode=Default}"/><br />
<br />
<CheckBox Content="AllowChange" IsChecked="{Binding Source={StaticResource ValueSource}, Path=AllowChange, Mode=Default}"/><br />
<br />
</StackPanel><br />
<br />
</Window><br />
Sincerely,
-Ron
|
|
|
|
|
See this thread for a similar issue, there is a workaround posted but in your case binding the ToggleButton's Enabled property to AllowChange might be better.
|
|
|
|
|
Hi !
Can we export a WPF window grid to Html page. I have to generate a report on WPF grid and then save the report on system in html format.
Karunish Arora
|
|
|
|
|
This[^] might help. It's a XAML to HTML converter.
|
|
|
|
|
I've encountered a strange problem in my WPF app. Basically, something appears to be killing all of my Command CanExecute methods.
Every UI element that has a Command tied to it will be disabled after certain operations, while most other times they will function normally. Calling a dialog such as MessageBox.Show("Really?", MessageBoxButton.YesNo) then executing my code will cause the problem.
Even UI elements with the most simple CanExecute such as this will be disabled after the dialog is shown.
private void Cmd_Exit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
Adding CommandManager.InvalidateRequerySuggested(); into the methods does not help.
Once they get disabled, clicking something active in the window will return normal behavior.
I've exhausted all of the things that I know of to try to find out what is causing this problem. Where should I go from here? I feel that it's something in the bindings that is the problem but bringing up the debugger causes the behavior to change.
|
|
|
|
|
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
|
|
|
|
|
RNEELY, thanks for your reply.
I will try to reproduce this in a sample app after I finish moving most of the code out of the window class and into the MasterList class. For the time being the entire source for the application is available:
http://sourceforge.net/projects/subhub/[^]
In my testing so far, the closest I have come to narrowing down the problem is in the following code block involving a MessageBox:
private void Cmd_CloseDir_Executed(object sender, ExecutedRoutedEventArgs e)
{
SetUiAsBusy();
if (MessageBox.Show(this, "Do you really...", "Confirm close", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
DirTreeNode theDirTreeNodeToRemove = MainTree_GetSelectedDirTreeNode();
MasterList.RemoveDirTreeNodeAndChildren(theDirTreeNodeToRemove, true);
MasterList.FillUniqueLists();
MasterList.FileMatches.Clear();
}
SetUiAsFree();
}
When the method is run, if you select Yes from the MessageBox the problem will surface. If you select No then it will not. If I comment out the if (MessageBox.Show statement and just let the code run then the problem WILL NOT show up.
From what I can tell, the problem seems to show up when dialogs and background processes are involved.
I'll work to reproduce this in a sample this weekend.
|
|
|
|
|
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 was made with the Wpf template.
Here's the SetUiAsBusy method:
private void SetUiAsBusy()
{
MasterList.UiIsFree = false;
NotifyPropertyChanged_All();
CommandManager.InvalidateRequerySuggested();
}
The SetUiAsFree method is the same except it is set to true. The UiIsFree variable is bound to the IsEnabled property of many UI elements.
In the method I posted earlier, MasterList.RemoveDirTreeNodeAndChildren(theDirTreeNodeToRemove, true); is where nearly everything happens. Several ObservableCollections are modified (safely as best as I can tell) that are bound to UI elements. No exceptions are getting swallowed and the VS output pane remains empty while the method runs.
|
|
|
|
|
Hi all,
at the moment I'm looking for a method to interact with the GUI components without using the mouse (i.e. the click on a button, or the drag and drop of a component in a Canvas).
I have an homebrew external devices that gives me just the coordinates of a point in the screen and the state of the click (down or up).
I know that I can control the mouse pointer using this device but I do not want to interfere with the mouse movements.
Could you help me?
Thanks in advance.
|
|
|
|
|
Dear all,
I am working on a 3D application using WPF. I am importing a 3D file in a viewport and i am doing some modification on that object( Move some of the object..)
I would like to make a sort of refresh of my figure to take in consideration the new changes( The equivalent of update in the windows Form). I am using the Thread.Sleep(1000);
to make the sleep .
Thanks you for your help.
Sondos
|
|
|
|
|
Hi,
I want to know whether i can load DWF/DXF/DWG files in my WPF application.I've searched a lot for loading these files.But,i didnt get any answer.Is that possible to import directly or should i convert the files into XAML format,since am working with WPF framework??I've even searched for XAML conversion of those files.But i could not find anything..Kindly suggest me..
Regards,
Priya
|
|
|
|
|
You are going to have to convert them I'm afraid - they are CAD files. However, you might be able to take advantage of something like this[^].
|
|
|
|
|
Have a look at CadLib[^], which supports displaying DWG and DXF files in WPF applications. There's a sample solution included in the evaluation version that demonstrates how to do it.
Wout
|
|
|
|
|
Hi All,
I need to make an application single instance, I've read and seen a few examples of doing this but none have really touched on WHERE to do this. In a WPF application with a normal App class inheriting from Application is this the best place to perform this check?
I'm looking at the Adam Nathan book which has a code sample, but putting this into the App class doesn't seem to work (this wont compile!):
public partial class App : Application
{
bool mutexIsNew;
using (System.Threading.Mutex m = new System.Threading.Mutex(true, "uniquename", out mutexIsNew))
{
if(mutexIsNew)
else
}
}
Looking at this MS example http://msdn.microsoft.com/en-us/library/ms771662.aspx[^] rather than using a mutex (which seems the best way) they import a visual basic namespace into a csharp app!!
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
You need to change the startup class so that it points to the one that has your Main method. This is accomplished by changing the Properties for your application in VS solution explorer. Look for the Startup Object list and choose your class. Note that you normally don't need to do this because VS automatically creates the Main based on the XAML app template. So, your main class would look something like this:
public class MyApp : Application
{
private static bool newMutex;
public static void Main()
{
using (Mutex m = new Mutex(true, "myApplication", out newMutex))
{
if (!mutexIsNew)
}
}
}
|
|
|
|
|
Hi Pete,
Thanks for this. I just popped off and made a StartUpObject.cs file and popped this code in there, then I changed the properties as you describe and the rest of my Presentation Layer UI stuff is blowing up. Popping this code into the App.xaml.cs is telling me that there is already a Main with the same parameter types. Should I be using the 'normal' App.xaml.cs or should I be creating a XAML file to go with my new StartUpObject.cs file?
EDIT:
Ok, I found some more info on the net and have done this but i'm now seeing binding errors so this isn't a good solution either:
Removed the StartUpUri="" from App.xaml and added this to my App.xaml.cs:
public partial class App : Application
{
private static bool mutexIsNew;
public App() : base()
{
using (Mutex m = new Mutex(true, "MyApp", out mutexIsNew))
{
if (mutexIsNew)
{
AppMainWindow mainwindow = new AppMainWindow();
mainwindow.Show();
}
else
{
App.Current.Shutdown();
}
}
}
}
Sorry for not getting this yet pete ...
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
modified on Friday, June 20, 2008 6:37 PM
|
|
|
|
|
If you can wait till Monday (when I'm back in the office), I can send you the startup code that we use - I'll drop it into a sample app for you.
|
|
|
|
|
That would be awesome Pete. Thank you!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer - here's a quick sample for you to try out:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Threading;
namespace SingleInstanceApp
{
public class SIApplication : Application
{
private static bool isNew;
[STAThread]
public static void Main()
{
using (Mutex m = new Mutex(true, "SIApplication.Mutex", out isNew))
{
if (isNew)
{
SIApplication app = new SIApplication();
app.InitializeComponent();
app.Run();
}
}
}
public void InitializeComponent()
{
this.StartupUri = new Uri("Window1.xaml", System.UriKind.Relative);
}
}
} Predictably, you need to set the startup object to point to this class. The trick is that you physically aren't going to create any other instances of the app because you have detected the state of the mutex before you create an instance of the app. BTW - you really need to use the StartupUri, I suspect this is where you've been getting your problems.
|
|
|
|