|
Thanks. I tried that code (from a different web site) some months back for another project and it did not work. However, after reading your post I found the one below which works:
c# - Stop TabControl from recreating its children - Stack Overflow[^]
It is the exact same control class as per your link, but with the addition of a style in the XAML. I cannot as yet see why the syle makes the difference to the behaviour.
Thanks again, very helpful.
|
|
|
|
|
I am not familiar with silverlight application, can anyone suggest if there is a way to automate the silverlight application using testng - selenium - java framework.
|
|
|
|
|
I've not used selenium but there seems to be quite a few who have! Google[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I found some supports like silvernium which are used for selenium, but not for eclipse java. still finding the solution
|
|
|
|
|
Good Day all
i am working on a Kinect Sensor Program, but i think this question can best be answered by the WPF forum.
In my Kinect Project , the User can use Kinect Gestures or Voice Commands. THe Gestures work nicely its like one is using a mouse. i have a challenge with the Voice Commands which follow a certain Process. Please note that this functionality works well when one is not using voice commands.
Let me make a simple example.
i have a 3 Buttons
Button 1 = "System Ok "
Button 2 = " View Error"
Button 3 = "System Reboot"
Step 1: Now the logic say , if a user enter a wrong command , the System must play a sound for Error and the button for " View Error" must Animate.
Step 2: The Rule goes on and say if the User has not click the " View Error" within 5 seconds , Stop the Animation on the " View Error"
Step 3: and Animate the "System Reboot" and play the Sound for "System Reboot"
Now on a normal button click with a Mouse , this would work. But now i am not clicking the Button Physically, i am using Voice Commands and i have trapped the SpeechRecognized event which is defined like this
private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
const double ConfidenceThreshold = 0.3;
const int DegreesInRightAngle = 90;
const int DisplacementAmount = 60;
this.ClearRecognitionHighlights();
if (e.Result.Confidence >= ConfidenceThreshold)
{
switch (e.Result.Semantics.Value.ToString())
{
case "VIEWERROR":
Error_Escaped = true;
btnViewError_Click(null, null);
break;
case "SYSTEMREBOOT":
btnSystemReboot_Click(null, null);
break;
case "SYSTEMSTATUS":
SystemStatus_Click(null, null);
break;
}
}
else
{
this.Status.Content = Properties.Resources.GrammarConfidenceLow;
Logger.NormalLog("The Confidence is low , the Grammar is not Recognised as a Command", Generics.Generics.ActivePage) ;
}
}
as you can see i am clicking the Buttons programmatically. So if i don't click the "View Error" button within 5 seconds , the System Reboot will start playing another sound.
That was about the Process. Now my challenge is that. After i used a wrong option according to my Process, the "View Error" button will give a sound and i will give a Voice Command to Stop the Sound , the next in the Process will still be fired. So i debugged the code and i realised that the Program , runs all the code that was running and when its done, it hit the "SpeechRecognized" event later, i want to intercept and give the Voice Command the same ability as a button click done with a mouse can do.
This is a function that runs , when there is an Error
private void ViewError()
{
Error_Escaped = false;
ResetBlinking(this.btnViewError);
AnimateButton(this.btnViewError);
Generics.Generics.WaitNSeconds(5);
if (Error_Escaped == false)
{
SystemReboot();
}
}
This will set the Flag for "Error_Escape = false " Which means no one has clicked the button. and it will Animate the Button and wait for 5 second which is my custom interval calculator. Now while its waiting i would keep saying some Voice Command to Stop it. it will still continue while i wait , it will jump to System Reboot which will have its sound. i want the
SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
event to fire when i need it not after the other event of buttons are fired.
Tanks
Vuyiswa Maseko
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
I would launch a timer from ViewError(); instead of putting it into a wait state.
The speech recognition event can kill the timer if it still running; else the timer sets off whatever needs to be done after time has elapsed.
(A basic "timeout" pattern).
|
|
|
|
|
I'm working on a WPF application for my company that can show the routing of cables on picture.
The Goal is to let the user choose a Part Number of a cable and the cable routing will be shown on the picture of the tool.
I will make two kinds of Access Control:
- Guest - that give only Read-Only access
- Admin - that will give the possibility to change the route on the picture (for example: adding new points, adding labels and connections between points) with Admin Panel
My problem is that i can't move the Label with the mouse, it's working with the point (the point is Path) and the Line.
Also i would like to understand why when i'm clicking on the Label it recognizes it like a TextBlock.
Here's my code:
public void Label_Edit_Mode(MouseButtonEventArgs e, Canvas canvas, bool lbledit)
{
if (lbledit == true)
{
IInputElement clickedElement = Mouse.DirectlyOver;
if (clickedElement is TextBlock)
{
label = clickedElement as TextBlock;
Mouse.Capture(label);
captured = true;
Vector offset = VisualTreeHelper.GetOffset(label);
x_label = offset.X;
x_canvas = e.GetPosition(canvas).X;
y_label = offset.Y;
y_canvas = e.GetPosition(canvas).Y;
}
}
}
public void Move_Points(MouseEventArgs e, Canvas canvas, bool isclicked)
{
if (e.LeftButton != MouseButtonState.Released)
{
if (captured == true && isclicked == false)
{
double x = e.GetPosition(canvas).X;
double y = e.GetPosition(canvas).Y;
{
if (path != null)
{
x_path += x - x_canvas;
Canvas.SetLeft(path, x_path);
x_canvas = x;
y_path += y - y_canvas;
Canvas.SetTop(path, y_path);
y_canvas = y;
}
else if (label != null)
{
x_label += x - x_canvas;
Canvas.SetLeft(label, x_label);
x_canvas = x;
y_label += y - y_canvas;
Canvas.SetTop(label, y_label);
y_canvas = y;
}
else if (line != null)
{
x_line += x - x_canvas;
Canvas.SetLeft(line, x_line);
x_canvas = x;
y_line += y - y_canvas;
Canvas.SetTop(line, y_line);
y_canvas = y;
}
}
}
}
else
{
captured = false;
}
}
here's a picture of how my application looks like:
[My App]
Thank you for your help
|
|
|
|
|
Dadou55 wrote: Also i would like to understand why when i'm clicking on the Label it recognizes it like a TextBlock.
Look at the remarks on the Mouse.DirectlyOver property:
Controls can be composed of multiple elements. DirectlyOver reports the specific element in the composite control the mouse pointer is over and not the control itself. For example, depending on which part of a Button the pointer is over, the DirectlyOver property could report the TextBox of the Content property or the ButtonChrome .
A Label[^] is a ContentControl . When you add text to it, that gets added as a TextBlock . When the mouse is over the text, DirectlyOver returns the TextBlock from the Content part of the Label control.
Basically, you're looking at the visual tree, not the logical tree. You'll need to use VisualTreeHelper.GetParent[^] to walk up the visual tree until you find the control you're looking for.
Trees in WPF[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I want to group , ungroup canvas user control in wpf application.Though this can be achieved with microsoft visual studio in built function Group and Ungroup which we get from Object and Timeline window.Through ungrouping we are removing unwanted canvas and making only one parent(canvas) to child controls.
Phis i need to achieve programmatically.Please suggest how can I achieve this through programmatically though I want to process my xaml file without doing this manual step and handle it through code behind.
Below mentioned is code snippet of xaml data which is not yet grouped and after that grouping.
Code before ungrouping :
<Canvas Name="_01" RenderTransform="1, 0, 0, 1, 130.919685, -4.32">
<Canvas Name="_64" RenderTransform="-0.999991, 0.004316, -0.004316, -0.999991, 14.637921, 2145.991988">
<Path Name="_64_G0__MrkrEnd" Visibility="Collapsed" RenderTransform="3.31258, -1.721798, -1.721798, -3.31258, 5.998991, 1066.51392" StrokeLineJoin="Round" Data="M -1 -1 L 0 0 L 1 -1 ">
</Path>
</Canvas>
</Canvas>
Code after Ungrouping and grouping into a canvas, which allow a single parent node to the child.
<Canvas Name="_01" RenderTransform="1, 0, 0, 1, 130.919685, -4.32">
<Path x:Name="_64_G0__MrkrEnd" Visibility="Collapsed" StrokeLineJoin="Round" Data="M -1 -1 L 0 0 L 1 -1 " Canvas.Left="14.637" RenderTransformOrigin="0.5,0.5" Canvas.Top="2145.992"/>
</Canvas>
|
|
|
|
|
Since WPF is one of your "specialties", you would know that most "container" controls have a "Children" collection; and to "ungroup" and (re)group controls, you remove them from one collection, and add them back to another collection (of a different "parent" control).
|
|
|
|
|
We are building a WPF project to control a machine. The machine is controlled by a PLC, and link to the PLC is with OPC.
The update from the PLC is done via reflexion, so the 'set' is called, but the disadvantage of this is that the value is written to the PLC again via 'SetValueToPlc()' see example.
The easy solution would be to copy all properties with a Write to PLC variant, but since our project already contains more than 2000 properties this is not the prefered solution.
The way I'm thinking is to make use of a template like the Nullable, and create 2 separate 'setters'. One which is coupled to the ViewModel for updates from the View and business-logic. And the other can be use by the OPC updates (reflection). The implementation from the last would be without writing the value back to the PLC.
So my question is how to make such a template, or are there other sugestions?
Example property:
[OpcItem("Simulate")]
public Boolean Simulate
{
get { return _simulate; }
set
{
_simulate = value;
SetValueToPlc(MethodBase.GetCurrentMethod().MethodHandle, value);
RaisePropertyChanged();
}
}
|
|
|
|
|
If you're worried about "redundant updates to the PLC", you should start by checking for a "value change" in the setter instead of blindly using the value.
|
|
|
|
|
The problem is when a value is only changed shortly in the plc. Eg a reset, goes to True, and the next cyclus is reset to false. The value true is set to the OPC point (old value was false, so this is updated to true, en send to the PLC again. But the plc already handled this True, so it will get an other reset (was already false and is reset to true). So one reset will lead to a second reset.
The update rate of OPC is slower than the PLC so this will stop after the second.
|
|
|
|
|
If I'm dealing with devices / services / threads that operate at different speeds but need to be "synchronized" somehow, I may use a "queue".
One "device" adds to the queue; the "other" takes from the queue.
If the queue may "overflow", then a method is formulated to remove "redundant" queue entries without processing them; e.g. false -> true -> false.
With "temperature" PLC's for example, I only need to be aware of when the temperature "changes" (as when plotting over time).
|
|
|
|
|
Hi Gerry,
Thank you for thinking with me here. Your solution works fine for keeping the right last value, i agree with that. But since it's a 2 way channel, I need to prevent the write back. So in my excample, when the PC 'Reset' is set to true, the plc -> true (after proccessing goed to false), this false is set to the PC. And all is fine.
But is the PLC internal set to True (internally is reset to false), -> PC receives True, and set's the reset to True again in the PLC. This last set is the one I try to prevent, The set is done via OPC reflection, so I should be able to distiguage this from an update from the ViewModel.
|
|
|
|
|
Yes; you can probably determine who called the setter by accessing the previous StackFrame(s) in the setter. Add the check to the "property changed" delegate; e.g.
StackFrame stackFrame = new StackFrame( 2, false );
MethodBase methodBase = stackFrame.GetMethod();
string source = string.Format( "{0}.{1}()", methodBase.DeclaringType.Name, methodBase.Name );
|
|
|
|
|
Never use the StackFrame like this. It has a disturbing habit of behaving differently between debug and release mode. It also behaves erratically if you have yield or await above the in the call chain.
This space for rent
|
|
|
|
|
It's a sample call.
I actually "walk" the stack; but including the code for that would cloud the original question; like your comment.
|
|
|
|
|
Thanks Gerry and Pete,
This might work, but requeres a lot of code in all my properties. Thats why I prefeur a solution with a second set methode. Analog to the get/set implementation of a Nullable.
|
|
|
|
|
Why does it require "a lot of code in all my properties"?
You're calling "Property Changed" anyway; add any "extra" code in there.
Then there's reflection; you've already used it in one instance.
|
|
|
|
|
He Gerry,
I misread your proposal. I think this could work as we. I'll try this and let you know.
Thanks for your aid!
|
|
|
|
|
I have an WPF XAML application where I need to capture a portion of the page and send it to the printer. I have gone through the Microsoft print dialog control reference and see how I can save an xps formatted document then load it into the print dialog and send it to the printer. Now I have read an article indicating that all I have to do is create a FixedDocument and bind my values to it's datacontext and then save the completed FixedDocument, reload it and send it to the pring dialog as an xps file which is what I want. The fixed page XAML is shown below:
<FixedDocument
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xml:lang="en-au">
<FixedDocument.Resources>
<BooleanToVisibilityConverter x:Key="visConverter"/>
</FixedDocument.Resources>
<PageContent>
<FixedPage Width="793.76" Height="1122.56">
<!-- Page 1 Begins Here -->
<StackPanel Margin="50">
<Border BorderThickness="5" BorderBrush="Gray" CornerRadius="10"
Padding="20" Width="690">
<StackPanel Orientation="Horizontal" Margin="0 0 0 0">
<Image Source="truck.jpg" HorizontalAlignment="Left"/>
<TextBlock Margin="30 0 0 0" FontSize="50"
Text="{Binding Path=Heading}" VerticalAlignment="Center"/>
</StackPanel>
</Border>
<TextBlock Margin="0 30 0 0"
Text="{Binding Path=CurrentDate, StringFormat='{}{0:d MMMM yyyy}'}"/>
<TextBlock Margin="0 30 0 0"
Text="{Binding Path=Name, StringFormat='Dear {0},'}" />
<ItemsControl Margin="30 20 0 0" ItemsSource="{Binding Path=DotPoints}"
HorizontalAlignment="Left">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,8,0,0" Orientation="Horizontal" >
<TextBlock Text="• " />
<TextBlock Text="{Binding}" TextWrapping="Wrap" Width="400"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Margin="0 30 0 0"
Text="Congratulations, you are entitled to a 50% discount!"
Visibility="{Binding Path=GiveDiscount,
Converter={StaticResource visConverter}}"/>
</StackPanel>
</FixedPage>
</PageContent>
<PageContent>
<FixedPage Width="793.76" Height="1122.56">
<!-- Page 2 Begins Here -->
<TextBlock Margin="50" Text="Nothing to see here."/>
</FixedPage>
</PageContent>
</FixedDocument>
Now when I try to add XAML to the page I get an error: Property 'pages' does no support a value of type 'PageContent.
Now I tried a different approach. Now to resolve this I have reviewed many articles until I came to one that looks like it will do the trick but it gives me an error as well. What error I get is it can not convert a FixedPage to an UIElement. The code is below:
<Window
x:Class="ODIN.DataSheetFixedDocument"
WindowStartupLocation="CenterScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:ODIN.View"
xmlns:local="clr-namespace:ODIN"
local:WindowCustomizer.CanMaximize="False"
local:WindowCustomizer.CanMinimize="False"
Title="Administrated Master View"
Width="1024"
Height="768"
>
<Grid Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="97*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="115*" />
</Grid.RowDefinitions>
<FixedPage Width="1024" Height="768" x:Name="theFixedPage">
<StackPanel Background="Green" Width="200" Height="30" HorizontalAlignment="Left" Margin="0,100,0,0" Grid.Column="0" Grid.Row="0">
<TextBlock Width="465" HorizontalAlignment="Left" Height="92" Foreground="Black" Margin="0,0,-265,0">Hello</TextBlock>
</StackPanel>
</FixedPage>
<DocumentViewer>
<FixedDocument x:Name="uiFixedDocument">
</FixedDocument>
</DocumentViewer>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ODIN
{
public partial class DataSheetFixedDocument : Window
{
public DataSheetFixedDocument()
{
InitializeComponent();
Grid grid = new Grid();
grid = (Grid)this.theFixedPage.Parent;
grid.Children.Remove(this.theFixedPage);
PageContent pageContent = new PageContent();
pageContent.Child = theFixedPage;
FixedDocument.Pages.Add(pageContent);
uiFixedDocument.Pages.Add(pageContent);
grid.Children.Add((UIElement) uiFixedDocument);
}
}
}
Now if I don't try to add it to the Grid it runs but my FixedPage does not display.
If anyone can see what I'm doing wrong help would be great.
modified 5-Oct-16 14:18pm.
|
|
|
|
|
I came up with an easy solution. Because I am only printing the XAML page that is being displayed, except for a few areas that I can collapse, here is what I did. On the XAML page it has a print stackpanel with the print button and header text I need to remove. After collapsing these elements I just use the PrintDialog PrintVisual(MainPageGrid, "Title"); method.
|
|
|
|
|
Hi,
That's really frustrating, some days ago I felt on a tutorial page on how to animate grids (or contentcontrol...I don't remember).
...and now that I need this page I can't find it again
There was an illustration like this (light blue squares)
http://i.imgur.com/PzcdoVs.png[^]
The principle being to animate scale in/out for centered object and opacity in/out for first and last object
Would you by chance see the page I'm referring to? (or at least lead me to a similar article!)
Thanks a lot!!
|
|
|
|
|
Try searching your browser history.
|
|
|
|
|