|
Yoyosch wrote: So fire up VS and see that ur answer is silly
Nope. I just ran it and it worked fine for me. Have you tried it?
|
|
|
|
|
Of course. This works in WinForms but not in WPF
|
|
|
|
|
There's nothing stopping you adding the WinForms reference to WPF and doing this.
|
|
|
|
|
Yoyosch,
Pete is trying to help you. Telling a Code Project MVP that his answer is silly does not promote good lines of communication. Thanks for working with us as we try and answer questions here.
Have a nice day.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Sorry I missed you at the MVP summit last week. I did, however, manage to speak to a few people that know you and you received some very high praise indeed.
|
|
|
|
|
Colin,
Me too. Don't know how we missed hooking up. Guess I'll just have to come and visit or get you to come to Charlotte!
Was very nice to meet so many cool and very smart developers. Super week for everyone.
Best to you always!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi there,
I have a stackpanel which contains another stackpanel in which I can browse with a previous and next button. The inside stackpanel contains images . I would like that there is no end in this stack. I mean that the last picture and the first one are joinded.
Thanks in advance,
Globosky
|
|
|
|
|
You are referring to a carousel. Infragistics has one and there are others you can dowload and learn from. You can use their's or write you own.
Check out the recent WPF Panel and WPF 3D Panel artciles here on Code Project.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Is it possible to use Ajax in WPF Browser Application ?
Best Regards
-----------------
Abhijit Jana
Microsoft Certified Professional
"Success is Journey it's not a destination"
|
|
|
|
|
Yes it is....
All depends on how do you want to make your communications to the server, but you will be enabled to do it ONLY with the server that send you the xbap... that means that if you are trying to run your app from VS2008 and it is configured to open your browser to the file repository you will be not able to test any AJAX, you need to publish it to an IIS and then your AJAX response should be on that same server instance. or at least on that host -no reference to a por number restrictions on the documentation-.
Greetings
Carlos de Luna
|
|
|
|
|
Hi colleagues,
I'm dealing with a weird scenario that I will try to explain here. I don't know what more can I do to find a solution, so I'm posting here with the expectation that someone can help me.
I created a user control using WPF & C# in .NET 3.5 with VS2008. This control is placed in a dll. The control has a toolbar, a tree view on the right side and a browser on the left. Inside the XAML code, I'm inserting the WebBrowser control hosted in a WindowsFormsHost. If I use this control from a Container that uses WPF as well everything works fine.
The problems arise when I try to call the mentioned control from an MFC application. I created a modeless dialog and call my WPF control. The first problem was that WM_CHARS messages were eaten up by someone, and I didn't receive any keystroke in my WPF control. Hopefully, I found this useful link that helped me to solve the problem:
http://devonethatdevelops.wordpress.com/2007/10/30/wpf-win32-interop-with-hwndsource/
But the main problem is that when I put the focus in the web browser and press the TAB key, both the modeless dialog and the application hang. The only thing I can do is go to the task manager and end the process. I've been searching similar problems but found nothing. I've tried to put breakpoints on every KeyDown event both in the containing dialog and in the user control but nothing happens. It seems as though the TAB key absolutely swollen by don't-know-who.
I've executed the WPF control from a WPF container and the KeyDown events reach my control on every key I press, but when I call it from the MFC dialog the program don't stop in the breakpoints.
The only thing I know is that pressing the TAB key inside the web browser control frozens the application.
Please, do you have any idea of what could be happening? Any clue?
Well, thanks anyway for having had the patience of reading this.
Oscar Ortega
|
|
|
|
|
Have you tried KeyboardNavigation.TabNavigation="None" for your user control ?
Sincerely,
-Ron
|
|
|
|
|
Thank you for your answer Ron. The problem is that I'm using the browser to display an InfoPath form, so the user will expect the TAB to be working "as usual" in order to change focus from control to control. So if I tell the user that he's going to lose the TAB key... well, maybe he's not going to be very happy.
But thanks, it's a good a idea if everything else fails to work.
Oscar
|
|
|
|
|
Anyway, Ron, I've just tested the solution you were proposing but no luck: it still happens the same. Application hangs. It seems as though the problem is more on the MFC side than on the WPF side, but it's only a guess...
Thanks,
Oscar
|
|
|
|
|
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
|
|
|
|