|
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
|
|
|
|
|
Hello again,
I've reproduced the problem in a small program. First, I've built a WPF Control Library with a WebBrowser embedded. Then, I've built a simple MFC application that calls this control. The result is the same: Whenever I press the TAB key inside the WebBrowser the application hangs and stops responding.
Next, I'm posting the code of this simple project. Please, could someone give me any clue about could be happening?
The WPF control library contains the following code:
In the XAML file:
<code>
<UserControl x:Class="WpfControlLibrary1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wfh="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Loaded="UserControl_Loaded"
Height="300" Width="300">
<Grid>
<wfh:WindowsFormsHost x:Name="myFormHost">
<wf:WebBrowser x:Name="webBrowser1" x:FieldModifier="public" />
<wfh:WindowsFormsHost>
<!-- Uncomment for WPF frame test
<Frame Name="myFrame" Source="http://www.google.es" LoadCompleted="Frame_LoadCompleted" />
-->
<Grid>
</UserControl>
</code>
Then in the .cs file:
<code>
namespace WpfControlLibrary1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
string destUrl = "http://www.google.es";
webBrowser1.Url = new Uri(destUrl);
}
/* Uncomment for WPF frame test
private void Frame_LoadCompleted(object sender, NavigationEventArgs e)
{
}
*/
}
}
</code>
For the application holding the WPF control, I've built a simple MFC application in which I added a class compiled with the /clr option to manage the transition between MFC (unmanaged) and WPF (managed). Following these lines is the code of this class:
<code>
{...}
#include <vcclr.h>
using namespace System;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Interop;
using namespace WpfControlLibrary1;
ref class Globals
{
public:
static System::Windows::Interop::HwndSource^ gHwndSource;
static UserControl1^ gwcContainer;
};
HWND hwndWPF; //The hwnd associated with the hosted WPF page
HWND GetHwnd(HWND parent, int x, int y, int width, int height)
{
System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew System::Windows::Interop::HwndSourceParameters ("MFCWPFApp");
sourceParams->PositionX = x;
sourceParams->PositionY = y;
sourceParams->Height = height;
sourceParams->Width = width;
sourceParams->ParentWindow = IntPtr(parent);
sourceParams->WindowStyle = WS_VISIBLE | WS_CHILD;
Globals::gHwndSource = gcnew System::Windows::Interop::HwndSource(*sourceParams);
Globals::gwcContainer = gcnew UserControl1();
FrameworkElement^ myPage = Globals::gwcContainer;
Globals::gHwndSource->RootVisual = myPage;
return (HWND) Globals::gHwndSource->Handle.ToPointer();
}
/// <summary>
/// Hooks to the HwndSource window procedure. This is required to handle a bug in the WPF interop
/// in case the HwndSource is used in a modal dialog. If the hook is not used, WM_CHAR messages
/// are lost because the standard dialog message loop includes a call to IsDialogMessage().
/// </summary>
static IntPtr ChildHwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, bool% handled)
{
if (msg == WM_GETDLGCODE)
{
handled = true;
//DLGC_WANTARROWS|DLGC_WANTTAB|DLGC_WANTALLKEYS|DLGC_RADIOBUTTON|DLGC_WANTCHARS
return IntPtr(DLGC_WANTCHARS);
}
return IntPtr(0);
}
// CWPFModelessContainerDlg dialog
IMPLEMENT_DYNAMIC(CWPFModelessContainerDlg, CDialog)
CWPFModelessContainerDlg::CWPFModelessContainerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWPFModelessContainerDlg::IDD, pParent)
{
}
{...}
int CWPFModelessContainerDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
hwndWPF = GetHwnd(this->GetSafeHwnd(), lpCreateStruct->x, lpCreateStruct->y, lpCreateStruct->cx, lpCreateStruct->cy);
// Message hook that ensures WM_CHAR messages are dispatched
// to the managed side. Try removing this line and then writing
// to the WPF TextBox
Globals::gHwndSource->AddHook(gcnew HwndSourceHook(ChildHwndSourceHook));
return 0;
}
{...}
void CWPFModelessContainerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
FrameworkElement^ page;
page = Globals::gwcContainer;
page->MinHeight = cy;
page->MaxHeight = cy;
page->MinWidth = cx;
page->MaxWidth = cx;
::MoveWindow(hwndWPF,0,0,cx,cy,TRUE);
}
</code>
I would appreciate your comments.
Thanks,
Oscar Ortega
|
|
|
|
|
I feel for you.... MFC and WPF don't play well when it comes to the keyboard. The best solution is to not mix controls! That said, other things you'll need to do to get tabbing kinda working:
1. Override pretranslate message in you App:
BOOL CMyApp::PreTranslateMessage(MSG* pMsg)
{
if (System::Windows::Interop::ComponentDispatcher::RaiseThreadMessage(*reinterpret_cast<System::Windows::Interop::MSG*>(pMsg)))
return true;
else
return CWinApp::PreTranslateMessage(pMsg);
}
2. Implement IKeyboardInfoSite and handle OnNoMoreTabStops. Call the MFC dialogs NextDlgCtrl method and return true:
In OnCreate:
((IKeyboardInputSink^) hwndWPF)->KeyboardInputSite = gcnew MyKeyboardInputSite(source);
bool GKeyboardInputSite::OnNoMoreTabStops(TraversalRequest^ request)
{
if (request->FocusNavigationDirection == FocusNavigationDirection::Next)
wpfDialog->NextDlgCtrl();
else
wpfDialog->PrevDlgCtrl();
return true;
}
The only problem with this is that tabbing back into the WPF user control puts the focus on the last control (not the first). Yet to figure out the best way to overcome that one.
Hope this helps
|
|
|
|
|
Hi everybody!
I am using DoubleAnimation to move some controls into view. Simplified structure of my window is as follows(I replaced smaller then with '[', and bigger than with ']':
[StackPanel]
[Canvas ClipToBounds="true"]
[Border]
[Panel]
[/Panel]
[More elements ... /]
[/Border]
[Border]
[Panel]
[/Panel]
[/Border]
...
[/Canvas]
[/StackPanel]
With the animation I am animating the Canvas.Top property of Border instance. While the animation is running Border element is visible, but the panel isnide the border has its Opacity property set to 0. The problem is that the animation is not running smoothly. Would it help if I set the visibility property of the panel to Visiblity.Collapsed or Visibility.Hidden. Could the reason for poor performance be that I am running in debug mode of VS2008?(For some reason I cannot switch to release mode). The application is running on Intel core 2 duo 1.83GHz cpu, and ATI mobility radeon X1600. Any advice will be welcome.
Thanks in advance,
Uros
|
|
|
|
|
Uros,
give this a try and post the results. Change the Opacity of all controls to 100%. Ensure that you are not using any BitMapEffects and lets us know how the animation works.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Please help me resolve the exception that get's thrown below when I try to run an app with one simple float dependency property. It is a default WPF window app with the following added to Window 1 to create a float dependency property:
<br />
public partial class Window1 : Window<br />
{<br />
public Window1()<br />
{<br />
InitializeComponent();<br />
}<br />
public static readonly DependencyProperty DependFloatProperty =<br />
DependencyProperty.Register("DependFloat",<br />
typeof(float),<br />
typeof(Window1),<br />
new UIPropertyMetadata(0.0));<br />
public float DependFloat<br />
{<br />
get { return (float)GetValue(DependFloatProperty); }<br />
set { SetValue(DependFloatProperty, value); }<br />
}<br />
}<br />
Following is the xaml:
<br />
<Window x:Class="Dependent.Window1"<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
Title="Window1" Height="300" Width="300"><br />
<Grid><br />
</Grid><br />
</Window><br />
When I run the app I get the following exception:
System.Windows.Markup.XamlParseException was unhandled
Message="Cannot create instance of 'Window1' defined in assembly 'Dependent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9."
Source="PresentationFramework"
LineNumber=1
LinePosition=9
...
Sincerely,
-Ron
|
|
|
|
|
Your dependency property is declared incorrectly. Basically, it's not seeing the 0.0 as a float. Try replacing it with
public static readonly DependencyProperty DependFloatProperty =
DependencyProperty.Register("DependFloat",
typeof(float),
typeof(Window1),
new UIPropertyMetadata((float)0));
|
|
|
|
|
Yes that worked. Thanks.
Sincerely,
-Ron
|
|
|
|
|
Hi,
I have created a listbox with items in XAML file using VS2008. (for a WPF Browser application)
I'm selecting a item with the mouse, and when I'm using the up and down keys of the keyboard and reach the top or the bottom of the listbox, it goes out the listbox.
Is there a way not to leave the listbox ?
I hope I'm clear enough in my explanation.
If anyone can help.
Thanks in advance,
Pat3d
My code:
<Page xmlns:my="clr-namespace:System.Windows.Shapes;assembly=PresentationFramework" x:Class="WpfBrowserStyleTest.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dropShadow="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
Title="Page1" Width="562" ShowsNavigationUI="False">
<Grid Height="263" Width="488">
<Grid.RowDefinitions>
<RowDefinition Height="176.346*" />
<RowDefinition Height="86.654*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="325.422*" />
<ColumnDefinition Width="162.578*" />
</Grid.ColumnDefinitions>
<dropShadow:SystemDropShadowChrome Color="#71000000" Margin="0,0,0,79.083" HorizontalAlignment="Left" Width="159.984">
<ListBox SelectionMode="Multiple" IsTabStop="False">
<ListBoxItem>test</ListBoxItem>
<ListBoxItem>test2</ListBoxItem>
<ListBoxItem>test3</ListBoxItem>
<ListBoxItem>test4</ListBoxItem>
<ListBoxItem>test</ListBoxItem>
<ListBoxItem>test2</ListBoxItem>
<ListBoxItem>test3</ListBoxItem>
<ListBoxItem>test4</ListBoxItem>
</ListBox>
</dropShadow:SystemDropShadowChrome>
<Button Grid.Column="1" Height="23" Margin="40.905,50.245,46.359,0" Name="button1" VerticalAlignment="Top">Button</Button>
</Grid>
</Page>
|
|
|
|
|
Try
<br />
<ListBox SelectionMode="Multiple" KeyboardNavigation.DirectionalNavigation="Cycle"><br />
Sincerely,
-Ron
|
|
|
|
|
Thanks Ron,
It's working fine with KeyboardNavigation.DirectionalNavigation="Cycle"
Pat
|
|
|
|
|
Hi everybody
I have a problem, for which, I don't seem to find the answer
I Created a User Control, in wpf. In that control I defined a Dependency Property as(all the smaller than signs are replaced with '[', and grater than signs are replaced with ']'):
public static DependencyProperty ItemsProperty = DependencyProperty.Register("Items", typeof(ObservableCollections[SomeClass]), typeof(MyUserControl), new PropertyMetadata(new ObservableCollection[SomeClass]);
I also implemented the standard Getter / Setter for that property as
public ObservableCollection[SomeClass] Items
{
get{return (ObservableCollection[SomeClass])GetValue(ItemsProperty)};
set{SetValue(ItemsProperty, value);}
}
In the constructor of the user control I subscribe to the CollectionChanged event as:
public MyUserControl()
{
InitializeComponent();
Item.CollectionChanged += new NotifyCollectionChangedEventHandler(items_CollectionChanged);
}
and in the event handler I have the code that does what is needed
private void items_CollectionCHanged(object sender, NotifyCollectionChangedEventArgs e)
{
//Build control foreach item in e.NewItems and add them to UI and remove from UI controls foreach item in e.OldItems
}
I add UserControls to my window as follows:
[StackPanel]
[local:MyUserControl]
[local:MyUserControl.Items]
[local:SomeClass .... /]
[local:SomeClass .... /]
[/local:MyUserControl.Items]
[/local:MyUserControl]
[local:MyUserControl]
[local:MyUserControl.Items]
[local:SomeClass .... /]
[local:SomeClass .... /]
[local:SomeClass .... /]
[local:MyUserControl.Items]
[local:MyUserControl]
[/StackPanel]
From the start everything worked fine, but if I add two or more instances of MyUserControl, to the window, the first instance is OK, but the other one contains also the items that was defined in the first one. For the example above one of the UserControls whould have 2 instances of control that is build in the CollectionChanged event handler, and the other one would have 5 of them. Does anybody know how to solve this problem. Any advice will be appriciated!
Uroš
<div class="ForumMod">modified on Monday, April 14, 2008 9:33 PM</div>
|
|
|
|
|
The problem is that the dependency property is static, therefore the default value only gets initialized once and the same collection is used for all the controls. In the dependency property use the default null and create the collection in the constructor.
See http://msdn2.microsoft.com/en-us/library/aa970563.aspx
|
|
|
|
|
Great. That solved my problem. Thanks
|
|
|
|
|
hi,
anybody know how to get the photo gallery using silver light
plz reply me...
Rajendran.AL
|
|
|
|
|
Hello,
Have you tried using this project[^]? It seems pretty nice..
There are a lot of samples in Silverlight Gallery[^]. You can probably find the sample that you want.
|
|
|
|
|
thanks alot.
Rajendran.AL
|
|
|
|
|
Hi All,
I want to use DataGridView which should be editable in my WPF application.
In Form Base application we can simply use DataGridView But here i am
unable to use it, what cade i have to written in XAML.
So Please any body suggest me what i have to do to use DataGridView in WPF.
Thanks
Bankey
|
|
|
|
|
Bankey,
You can download and use distribute for free, the datagrid controls from eXceed or Infragistics.
You can also write you own, depending on how much functionality you require.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Karl Shifflett wrote: You can also write you own, depending on how much functionality you require.
It's surprising that more people don't do this - considering how easy it is to extend and restyle controls like the ListView.
|
|
|
|
|
If you don't want to download something like the Infragistics or Exceed grids (and really you should look at them - they are very good), you could always host the WinForms DataGridView.
If you're running VS 2008, the steps to do this are:
1. Reference System.Windows.Forms and WindowsFormIntegration in your project.
2. Add a WindowsFormsHost element to your XAML and put the grid inside
:<WindowsFormsHost Height="100" Width="200">
<wf:DataGridView x:Name="dg" />
</WindowsFormsHost> 3. Add the following declaration to your XAML:
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
|
|
|
|
|
Pete,
I'll be off line starting tomorrow and will be back on line 28 April.
I'll try and gets of pictures. I didn't get any at MIX08 so I guess I should for this trip.
Cheers!!!
Karl
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Karl Shifflett wrote: I'll try and gets of pictures. I didn't get any at MIX08 so I guess I should for this trip.
Cool. I'll try to hold the fort here while you're away Enjoy your trip.
|
|
|
|
|
Pete O'Hanlon wrote: I'll try to hold the fort
When they starting piling up, remember the Alamo! Do leave you post!! LOL...
Josh & I have classes together over there will be a great time!
Thanks!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Karl Shifflett wrote: Josh & I have classes together over there will be a great time!
I'm jealous. I bet that's one hell of a time.
|
|
|
|