|
Thanks Abhinav, however i am looking for some clean way of handling user preferences. Please refer my previous post for more information.
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
[EDITED: removed extra backslash from first example. It was copy/paste error]
I am trying to open a WPF window from VB6. I have a .NET 4.0 dll that has four WPF windows and several C# classes in it. Three of the WPF windows open without any errors. The fourth keeps giving me "Run-time error '-2146233087 (80131501)': Automation Error" when InitializeComponents() is called.
I believe it has something to do with what is in the XAML code. Here is an abridged version of what is in the windows that work:
<Window>
<Grid>
<CustomTextBox />
<CustomTextBox />
<Label />
<Label />
</Grid>
</Window>
The three windows using the above format have one method, ShowWindow(), exposed so I can display it from VB6 (no comments about I could have overridden the Show() or ShowDialog() methods please).
Here is the XAML for the window that is not working:
<Window>
<Window.Resources>
<XmlDataProvider x:Key="configdata"/>
<XmlDataProvider x:Key="servodata"/>
</Window.Resources>
<Grid>
<TabControl>
<TabItem>
<Grid>
<ScrollViewer>
<TabControl ItemsSource="{Binding Source={StaticResource configdata}, XPath=PROGRAM/CONFIG_PAGE}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=@page_title}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<toolkit:DataGrid ItemsSource="{Binding XPath=DATA}">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding XPath=DESCRIPTION}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=VALUE}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</ScrollViewer>
</Grid>
</TabItem>
<TabItem>
<Grid>
<TabControl>
<TabItem>
<Grid>
<toolkit:DataGrid ItemsSource="{Binding Source={StaticResource configdata}, XPath=IO/Inputs/Input}">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding XPath=DESCRIPTION}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=VALUE}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=METRIC_VALUE}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</Grid>
</TabItem>
<TabItem>
<Grid>
<toolkit:DataGrid ItemsSource="{Binding Source={StaticResource configdata}, XPath=IO/Outputs/Output}">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding XPath=DESCRIPTION}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=VALUE}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=METRIC_VALUE}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</Grid>
</TabItem>
</TabControl>
</Grid>
</TabItem>
<TabItem>
<Grid>
<toolkit:DataGrid ItemsSource="{Binding Source={StaticResource servodata}, XPath=DATA}">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding XPath=DESCRIPTION}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=VALUE}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=METRIC_VALUE}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</Grid>
</TabItem>
</TabControl>
<Button/>
<Button />
</Grid>
</Window>
The Interface for this window has the same ShowWindow() method plus a boolean property exposed.
I have a tester app with this dll to show the windows and make sure they work before putting them on the VB6 machine. I have ran it on the VB6 machine and the big window works fine. It accesses the XML files it needs to, writes to them, reads from the registry. It all works fine.
I have been working on this for 3 days now and cannot figure out what is wrong. Originally none of the windows would work, but I figured out that my regasm command line was missing the /tlb option. Again, all the other windows work fine and this one works when opened with the tester executable, just not the VB6 executable.
Any help is appreciated.
Brad
Deja Moo - When you feel like you've heard the same bull before.
modified 27-Jan-12 14:43pm.
|
|
|
|
|
I'm not sure if it's just a typo on your part or not but your ending shouldn't have the second backslash.
|
|
|
|
|
Thanks, but I don't see the second backslash you are referring to, but I bet it's a typo. The form shows fine when ran through the .NET test application.
Nevermind, I see it now. It has been correct. The first window is the one that shows without problems. I'm having problems displaying the second example.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
Its giving you a runtime exception because it failed to create the WPF window. Your constructor and/or InitializeComponent() is throwing the exception. You are just catching it about 57.8 million layers too high, so you can't see the real exception. You can try drilling down the inner exceptions or put a try / catch in the WPF code on the entire constructor and pop up a message box with the real exception or use WinDbg to catch the first chance exception. Once you see the REAL exception, it'll spell things out in plain English .
|
|
|
|
|
SledgeHammer01 wrote: You are just catching it about 57.8 million layers too high
I wish that was an exaggeration.
I had put message boxes in the constructor and narrowed it down to the InitializeComponent(). I never thought to go one step further with the try/catch even though I have a hundred throughout my code.
Thanks for beating my with the obvious stick. Sometimes you get so focused trying to nail a bug you make it a bigger deal than it really is.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
Why explicit Style defined in a theme Which had been applied for one control aren't update when change the Theme ?.
Main.xaml: (This is a resume of main.xaml , to see full have a look the attached file)
<UserControl>
<Grid x:Name="LayoutRoot" Background="White" >
<Border Style="{StaticResource BorderStyle2}">
<Button Click="Change_to_Dark_Click"
Height="20">Select Dark Theme</Button>
</Border>
</Grid>
</UserControl>
Main.xaml.cs : (This is a resume of main.xaml.cs, to see full have a look the attached file)
private void Change_to_Dark_Click(object sender, RoutedEventArgs e)
{
//Cleannig
App.Current.Resources.Clear();
App.Current.Resources.MergedDictionaries.Clear();
Theme.SetApplicationThemeUri(App.Current, null);
Uri themeUri = new Uri("/Controls.Dark;component/Generic.xaml", UriKind.RelativeOrAbsolute);
Theme.SetApplicationThemeUri(Application.Current, themeUri);
//The theme changed but the style of Border doesn't change.
}
There is a Controls project "Controls.csproj" (to see full have a look the attached file) with:
Generic.xaml
Style.xaml
ButtonCustomized.xaml
There are 2 themes projects created like this "Controls.Dark.csproj" (to see full have a look the attached file):
Generic.xaml
Style.xaml
Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Controls;assembly=Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Controls.Dark;component/Style.xaml" />
<ResourceDictionary Source="/Controls;component/Themes/ButtonCustomized.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Style.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="KeyColor">#FDB800</Color>
<Color x:Key="KeyColor2">#FBD8AB</Color>
<SolidColorBrush x:Key="KeyColorBrush"
Color="{StaticResource KeyColor}" />
<SolidColorBrush x:Key="KeyColorBrush2"
Color="{StaticResource KeyColor2}" />
<Style x:Key="BorderStyle1"
TargetType="Border">
<Setter Property="Background"
Value="{StaticResource KeyColorBrush}" />
</Style>
<Style x:Key="BorderStyle2"
TargetType="Border">
<Setter Property="Background"
Value="{StaticResource KeyColorBrush2}" />
</Style>
</ResourceDictionary>
I don't know why the explicit style doesn't are updates when change theme of the application?
Thanks for the future answers, regards.
Attached file in
http://silverlight.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=silverlight&WorkItemId=10224&FileAttachmentId=3800[^]
http://silverlight.codeplex.com/workitem/10224[^]
|
|
|
|
|
Hello,
I am converting my application to Silverlight 5 from Silverlight 4.
I got following error while converting.
Could not load type 'System.Windows.Controls.VirtualizingPanel' from assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
Any help regarding that will be greatly appreciated.
Thanks
|
|
|
|
|
Try removing the dll reference for System.Windows.Control and add it again.
|
|
|
|
|
This is not really a question...
When working with WPF trying to implement the MVVM pattern, I feel like I spend all of my time writing code to jump through hoops so as to not violate the MVVM pattern's principles...
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
I feel the same way when starting a project. But once I get going, it does not seem so bad.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
It sounds like you are writing a lot of your own plumbing code there. Why not try a library like MVVM Light, or Cinch? These take a lot of the pain away for you.
|
|
|
|
|
Thanks Pete. I may give them a look. For my first go, I was trying to stick to basics, thinking that maybe it would help me understand things better, but now I see that I am getting buried in the niggling little details.
My other concern was trying to learn one more thing (i.e. MVVM Light) on top of everything else. I looked briefly at Caliburn Micro, and my head started spinning round, and I threw up my hands and said, "Run away!"
Now that I have a better feel for the basics, I might take another look at it (C.M.) at some point, but I think one of the ones that you suggested might be better for me at this point.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
No problem. I've written a couple of MVVM frameworks so I know the pain you've been going through. Had there been a mature, stable framework around when I first started, I wouldn't have bothered as I'm not a fan of reinventing the wheel.
|
|
|
|
|
I wrote my own MVVM framework probably 6 to 8 months ago. There were 10 to 12 open source ones available. I chose to reinvent (and improve) the wheel.
1) I didn't want the code cluster f*cked up with Silverlight (and other nonsense) support since I have no interest in that and it's a dead platform anyways
2) No MVVM framework out there provided 100% of the plumbing needed to write a full blown MVVM application. 50%? Absolutely. 75%? Probably. 90%+, sorry, but no.
You'd have to combine 3 or 4 open source projects to get to where I'm at I think. Now granted, I may not have all the features of those 3 or 4 projects combined, but I have what is needed to write a full blown MVVM application and they don't.
For example, none of them have a way of binding to multiple selection tree / list controls which I found to be quite important .
|
|
|
|
|
SledgeHammer01 wrote: No MVVM framework out there provided 100% of the plumbing needed to write a full
blown MVVM application. 50%? Absolutely. 75%? Probably. 90%+, sorry, but no
So what was missing? What features did you need that you couldn't get? Why could you not extend what was available?
|
|
|
|
|
Only a few "biggies", but most are the little bells and whistles:
1) no clean way to bind (both 1-way & 2-way) to a multiple selection list control (this is actually a WPF shortcoming, but my MVVM framework fixes it)
2) no clean way to 2-way bind to the selected item in a tree control (another WPF shortcoming)
3) no built in light weight DI container
4) no clean way to bind to item right clicks for context menus (without retemplating the item)
5) no way to bind to a password box
6) no single instance only support
7) no way to close a dialog or window from the VM
8) no way to disable the close on a dialog or window
9) no way to remove the window icon
10) no template-able task dialog
Thats just from a quick scan of my code base .
Don't get me wrong... sometimes I grab code as a foundation and build upon it... but in this case, I looked at the various code bases and decided I would start from a clean slate.
|
|
|
|
|
1. Fair enough
2. Hoo yes
3. Not strictly speaking, necessary for a MVVM framework (but you can do this with Cinch 2 - uses MefedMVVM)
4. Yup
5. Been there, seen it, got that t-shirt. In fact, I once blogged about this very issue.
6. Cinch 2 - via MEF
7. Cinch 2 - via MEF
8. Nope, but could be done with Cinch 2
9. Not really MVVM related.
10. Again, not MVVM - but I can see why you'd want it.
|
|
|
|
|
9 & 10... yeah, not MVVM related in the sense of being part of the MVVM pattern, but its something that I needed to do and couldn't with any framework. Typically, dialogs that do not appear in the task bar are not supposed to have icons.
|
|
|
|
|
Looking forward to your CP article on your framework
best, Bill
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare
|
|
|
|
|
Pete,
I've started using MVVM Light. I'm slowly pulling pieces of it into my implementation.
For example, I had written my own ViewModelBase class that encapsulates (is that the right word?) some common things that I needed for all of my classes. I changed the name of my base class and am now deriving it from Laurent's ViewModelBase, with all of my View Model classes still being derived from my modified base class. I was able to pull out some of the INPC stuff, etc. from my base class, and just use the MVVM Light implementation.
Likewise, I threw away my homegrown (based on some of your code in fact) RelayCommand class and am using the MVVM Light version. There was nothing wrong with the homegrown version, but Laurent's is a bit more flexible.
The Messenger class is the cat's a$$. I've found some good uses for that. I have not used the ViewModelLocator because I already had a scheme going that I like that was suggested to me by Collin Jasnoch, and it seems to be working well.
All in all, I feel I am getting there. Thanks for the suggestions and encouragement.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
Tom, I'm delighted that I was able to help here. Laurent has done a fantastic job with MVVM Light, and it is a good one to get up to speed with. Good job.
|
|
|
|
|
Now if I could just get so that all of the views that I have designed weren't ugly... But that's another whole issue.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
Personally, I prefer using the ViewModelLocator method vs. DataTemplates. Some people are the other way around.
I think the ViewModelLocator method is a lot cleaner and makes more sense. You load up a view and it should know how to do its own thing. Creating the VM first seems backwards to me.
IMO, you shouldn't be creating VMs by hand. You should leave that to the view locator and DI.
Also, the ViewModelLocator is 1 line in XAML vs. the DataTemplate method with is 3 lines of XAML + C# code to create the VM and set the DataContext.
|
|
|
|
|
I'll take your suggestions under advisement. For now, however, I'm going to leave that part of things alone. For this particular app, it is working well, and I have changed enough things around already. Maybe my next project. I need to get moving on this thing and get it finished up!
Thanks for the suggestions. I appreciate the input.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|