|
You have already posted this in QA[^]. You've been here long enough to know our opinion of reposts.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Roni,
I created a WPF with nested controls and its working fine, what i did was
Created 4 UserControls naming - UC1, UC2, UC3, UC4
As per the scenario stated in the question a UserControl is nested in another
The code is as below :-
UC1 XAML:-
<usercontrol x:class="TestWPF.Views.UC1"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns ="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="300">
<grid x:name="MainGrid">
UC1 CODE BEHIND:
private void Button_Click(object sender, RoutedEventArgs e)
{
this.MainGrid.Children.Clear();
this.MainGrid.Children.Add(new UC2());
}
UC2 XAML:-
<usercontrol x:class="TestWPF.Views.UC2"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns ="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="300">
<grid x:name="MainGrid">
UC2 CODE BEHIND:
private void Button_Click(object sender, RoutedEventArgs e)
{
this.MainGrid.Children.Clear();
this.MainGrid.Children.Add(new UC3());
}
Similary for UC3 and UC4
Try it let me if any problems
|
|
|
|
|
|
How to download a excel file in silverlight which is returned from wcf service in form of byte arrays ?
|
|
|
|
|
Sounds doable, so where are you stuck?
|
|
|
|
|
The content of Excel files is specific to Excel, and can only be converted by reading it via ODBC or Excel Interop.
|
|
|
|
|
|
OK, then please answer the question with the details rather than telling me this.
|
|
|
|
|
He didn't ask for something like that. His question makes no sense to me.
|
|
|
|
|
|
I just wanted to tell you for your own benefit (potentially) and clarify it for anyone else reading this thread.
|
|
|
|
|
Apart from saying that I am wrong you have not added anything that would be for anyone's benefit. Using the libraries that I suggested could (potentially) solve the OP's question.
|
|
|
|
|
Isn't it of anyones benefit who's interested to read/write Excel files to know that there are alternatives to ODBC/Interop!? Finding those libraries isn't hard work.
|
|
|
|
|
And you are certainly not going to help them.
|
|
|
|
|
|
So I took the code from a StackOverflow[^] question:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image Name="Image" Source="TwitterBirdsAttack.jpg" MouseMove="Image_MouseMove" MouseUp="Rectangle_MouseLeftButtonUp" />
<Rectangle Name="Rect" Width="100" Height="100" Fill="Transparent" Stroke="Red" StrokeThickness="5" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp" />
</Grid>
</Window>
Class MainWindow
Private moveRect As Boolean
Private trans As TranslateTransform = Nothing
Private originalMousePosition As Point
Private Sub Rectangle_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
originalMousePosition = e.GetPosition(Image)
moveRect = True
Rect.IsHitTestVisible = False
End Sub
Private Sub Image_MouseMove(sender As Object, e As MouseEventArgs)
If moveRect Then
trans = TryCast(Rect.RenderTransform, TranslateTransform)
If trans Is Nothing Then
trans = New TranslateTransform()
Rect.RenderTransform = trans
End If
trans.Y = -(originalMousePosition.Y - e.GetPosition(Image).Y)
trans.X = -(originalMousePosition.X - e.GetPosition(Image).X)
End If
End Sub
Private Sub Rectangle_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs)
moveRect = False
Rect.IsHitTestVisible = True
End Sub
End Class
Now, the first time I move the rectangle it behaves as expected. But once its settled in its new location, it starts over again in its original location. It did not matter what I tried, the second time I clicked the moved rectangle its settled in the middle of the screen.
I tried saving the last Transformation and use this before mouse move was initiated in Rectangle_MouseLeftButtonDown, but that didn't do any good it simply refused to move.
I'll bet its something obvious that I have missed, but I cant see it now.
|
|
|
|
|
Jippi, I get to answer my own question. The problem is that you have to force it to remember the last position.
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image Name="Image" Source="TwitterBirdsAttack.jpg" MouseMove="Image_MouseMove" MouseUp="Rectangle_MouseLeftButtonUp" />
<Rectangle Name="Rect" Width="100" Height="100" Fill="Transparent" Stroke="Red" StrokeThickness="5" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="trs" X="0" Y="0"/>
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
</Window>
The code behind:
Class MainWindow
Private moveRect As Boolean
Private trans As TranslateTransform = Nothing
Private originalMousePosition As Point
Private LastPos As New Point
Private Sub Rectangle_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
originalMousePosition = e.GetPosition(Image)
moveRect = True
Rect.IsHitTestVisible = False
End Sub
Private Sub Image_MouseMove(sender As Object, e As MouseEventArgs)
If moveRect Then
If LastPos <> Nothing Then
trs.Y = -(originalMousePosition.Y - e.GetPosition(Image).Y - LastPos.Y)
trs.X = -(originalMousePosition.X - e.GetPosition(Image).X - LastPos.X)
Else
trs.Y = -(originalMousePosition.Y - e.GetPosition(Image).Y)
trs.X = -(originalMousePosition.X - e.GetPosition(Image).X)
End If
End If
End Sub
Private Sub Rectangle_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs)
moveRect = False
Rect.IsHitTestVisible = True
LastPos.X = trs.X
LastPos.Y = trs.Y
End Sub
End Class
|
|
|
|
|
hi
in part of my WPF Application I need something like a day of calendar that has from up 00:00 to down 23:59 and I need to drag and drop the songs on it to get play in specific time. like a play list.
that's in my mind and I need to know how can I create that calendar day.
what kind of controls should I use? is there some code sample to help me to get some idea?
thanks
|
|
|
|
|
Rather than use a calendar control, which is a rather heavy duty object with lots of stuff around appointments etc, I would use a listbox or a treelistview which are much simpler collection controls.
I presume you do not need the appointment functionality.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
Please suggest me any way to achieve this functionality. I have one textbox1, when I enter any value to this textbox1 then it should update to other textboxes i.e. textbox2, textbox3, textbox4, textbox5.....
|
|
|
|
|
You need to use the ElementName property of the Binding :
Binding.ElementName Property[^]
WPF Data Binding - Part 1[^]
<StackPanel>
<TextBox Name="textBox1" />
<TextBox Name="textBox2" Text="{Binding ElementName=textBox1, Path=Text}" />
<TextBox Name="textBox3" Text="{Binding ElementName=textBox1, Path=Text}" />
<TextBox Name="textBox4" Text="{Binding ElementName=textBox1, Path=Text}" />
<TextBox Name="textBox5" Text="{Binding ElementName=textBox1, Path=Text}" />
</StackPanel>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard...
|
|
|
|
|
Hi,
I'm using SharpDX for DirectInput joystick management...and I can't resolve the problem I get while setting cooperative level
Imports SharpDX
Imports SharpDX.DirectInput
Imports System.Windows.Interop
Class MainWindow
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
MainForJoystick()
End Sub
Private Shared Sub MainForJoystick()
Dim directInput As New DirectInput
Dim joystickGuid = Guid.Empty
For Each deviceInstance As DeviceInstance In directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)
joystickGuid = deviceInstance.InstanceGuid
Next
If joystickGuid = Guid.Empty Then
For Each deviceInstance As DeviceInstance In directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)
joystickGuid = deviceInstance.InstanceGuid
Next
End If
If joystickGuid = Guid.Empty Then
Debug.Print("No joystick/Gamepad found.")
End If
Dim hwnd As IntPtr = New WindowInteropHelper(Application.Current.MainWindow).EnsureHandle()
Dim joystick = New Joystick(directInput, joystickGuid)
joystick.SetCooperativeLevel(hwnd, CooperativeLevel.Foreground)
Debug.Print("Found Joystick/Gamepad with GUID: {0}", joystickGuid)
joystick.Properties.BufferSize = 128
joystick.Acquire()
While True
joystick.Poll()
Dim datas = joystick.GetBufferedData()
For Each state As JoystickUpdate In datas
Debug.Print(state.ToString)
If state.Offset = 60 Then
If state.Value = 128 Then
Debug.Print("Up button pressed")
End If
End If
Next
End While
End Sub
End Class
The problem comes from here:
joystick.SetCooperativeLevel(hwnd, CooperativeLevel.Foreground)
SharpDX.SharpDXException was unhandled
HResult=-2147024809
Message=HRESULT: [0x80070057], Module: [SharpDX.DirectInput], ApiCode: [DIERR_INVALIDPARAM/InvalidParam], Message: Incorrect parameter.
Please would you please help me understand what I'm doing wrong? I've been searching for days to resolve this!!
Many thanks!
modified 23-Jan-15 12:18pm.
|
|
|
|
|
I have a very strange issue that I have been unable to resolve. I have a window that is opened on a new thread that contains a custom control box with the min, max, and close buttons as ellipses, with handlers attached:
<StackPanel DockPanel.Dock="Right" Name="ControlBox" Orientation="Horizontal" HorizontalAlignment="Right" Height="22" VerticalAlignment="Center" Margin="0,4,0,0" Background="LightGray" >
<Ellipse Margin="5,0,5,0" VerticalAlignment="Top" HorizontalAlignment="Right"
Width="14" Height="15" MouseLeftButtonUp="btnMinimize_MouseLeftButtonUp"
MouseEnter="ActivateTitleIcons" MouseLeave="DeactivateTitleIcons"
MouseLeftButtonDown="btnMinimize_MouseLeftButtonDown" Name="btnMinimize"
Fill="{StaticResource Min_inact}" Visibility="{Binding Path=MinimizeButtonVisible, Converter={StaticResource ResourceKey=BooleanVisibilityConverter}}"/>
<Ellipse Margin="0,0,5,0" VerticalAlignment="Top" HorizontalAlignment="Right"
Width="14" Height="15" MouseLeftButtonUp="btnMaximize_MouseLeftButtonUp"
MouseEnter="ActivateTitleIcons" MouseLeave="DeActivateTitleIcons"
MouseLeftButtonDown="btnMaximize_MouseLeftButtonDown" Name="btnMaximize"
Fill="{DynamicResource Max_inact}" Visibility="{Binding Path=MaximizeButtonVisible, Converter={StaticResource ResourceKey=BooleanVisibilityConverter}}"/>
<Ellipse Margin="0,0,5,5" VerticalAlignment="Top" HorizontalAlignment="Right"
Width="14" Height="15" MouseLeftButtonUp="btnClose_MouseLeftButtonUp"
MouseEnter="ActivateTitleIcons" MouseLeave="DeActivateTitleIcons"
MouseLeftButtonDown="btnClose_MouseLeftButtonDown" Name="btnClose"
Fill="{DynamicResource Close_inact}" Visibility="{Binding Path=CloseButtonVisible, Converter={StaticResource ResourceKey=BooleanVisibilityConverter}}"/>
</StackPanel>
As an example of the problem, here is the code for the minimize button's MouseLeftButtonDown and MouseLeftButtonUp handlers:
Private Sub btnMinimize_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
btnMinimize.Fill = CType(Me.Resources("Min_pr"), ImageBrush)
End Sub
Private Sub btnMinimize_MouseLeftButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
btnMinimize.Fill = CType(Me.Resources("Min_inact"), ImageBrush)
SystemCommands.MinimizeWindow(_parent)
End Sub
Now if I just run the application, when I click the minimize button it changes to the proper image but when I let go of the mouse button nothing happens; the window doesn't minimize. Same thing if I set break points anywhere in the btnMinimize_MouseLeftButtonUp method, however if I set a break point on the Private Sub btnMinimize_MouseLeftButtonDown ... line, then the window minimize as it should.
I have never come across this. How does the btnMinimize_MouseLeftButtonUp method run only if I set a break point on the Private Sub btnMinimize_MouseLeftButtonDown ... line? Any suggestions on how this can be resolves is greatly appreciated.
Thank You
A black hole is where God tried to divide by zero.
There are 10 kinds of people in the world; those who understand binary and those who don't.
|
|
|
|
|
All GUI stuff needs to be done on the main thread. Other threads are for work only.
|
|
|
|