Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

WPF TabControl's TabItem issue

$
0
0

Greetings,

I have a TabControl to which I'm binding headers and TabItem using ObservableCollection<myModelClass> and each TabItem will contain a UserControl, The first tab will have all the other tabs one after the other in a Grid i.e. one UserControl after the other will be placed in the first tab using ContentControl, The data for the tabs will populate when i do a search, When I click on the other tabs and then click on the first tab for the first time then everything works fine, but when I click on any other tab and click on the first tab then that particular tab ( i.e. the UserControl ) is gone from the first tab, Similarly whatever tabs I am clicking other than first tab those are popping out of the first tab, could anyone help me to resolve this, I am using MVVM pattern and I am no where instantiating the ViewModels again.

Thanks,

Abdul Mateen.


Video WebBrowser WPF

$
0
0

Hello 

i am using WindowsFormsHostto host webbrowser in my WPF application.

i can read successfully Youtube video .

but when i am trying to browse this page ,

http://www.bbc.com/news/uk-25218989.

i have Error.

please see my screenshot here 

https://onedrive.live.com/redir?resid=CECAAF65D29E2CA2%211029

if i browse the same URL in my  IE, the video play well.

i do not understand why this one is not playing in WPF browser.

Thanks in advance for your help


ListBox / GridSplitter resize problem when grid columns have MinWidth

$
0
0

Hi,

I have come across some strange behaviour when using a GridSplitter and a ListBox which contains large items (longer than the visible area) and the grid columns have a minimum width defined.

The problem is quite difficult to explain, so I have put together a sample project which demonstrates it.  This can be downloaded from http://cid-a65709b19f08d61a.office.live.com/browse.aspx/Sample%20projects.  It is the GridSplitter.rar file.

This is what you have to do to recreate the problem.

  1. After the application has started, maximise the window
  2. Drag the GridSplitter as far to the right as possible
  3. Minimise the window again

After doing this you will see that the buttons in the right column have been pushed off the window.  Initially I was also unable to adjust the GridSplitter after following this procedure.  I got around this problem by setting ShowPreview=True.

The problem does not happen if the ListBox does not have a horizontal scroll bar, so I am not certain if the problem is with the ListBox, GridSplitter or the combination of both.

I have seen other posts with reference to the GridSplitter resizing so expect it is the GridSplitter which is causing the problem.  Unfotunately, these posts either do not have a solution or do not correct the problem I am experiencing.

Thanks,
DocKimble

 

Datagrid Scrollbar Visibility

$
0
0

Hello

is it possible to display the scrollbar of the datagrid only if the mouse is over the datagrid?

when the mouse leave datagrid area, the scrollbar will disappear.

Thanks

Unable To Navigate To Different Pages

$
0
0

I Have Made A New Page Named Page1.xaml

I Am Using This Code

 NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));

But I Get An Error

WPF application crashes after setting label font family to a "bad" one

$
0
0

I have a ListView that display system fonts.  One of the fonts is Thorndale AMT.

Every time I mouse over a font, I have a preview area that displays the mouse-overed font.

I also have an option to select font style: italic/bold

When I select italic and mouse over the font Thorndale AMT, the application just crashes!  This only happens when font style is italic and Thorndale AMT.  I don't know how I can detect the problem and handle it nicer.  I hate WPF that every time it has a problem, it just doesn't display the message but shuts down the application.

Below is the exception, I appreciate any helps!

Exception type:  System.IO.FileFormatException
Message:         Input file or data stream does not conform to the expected file format specification.
Source:          PresentationCore
Target Site:     ConvertHresultToException

Stack Trace:
   at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32
hr)
   at MS.Internal.Text.TextInterface.Font.CreateFontFace()
   at MS.Internal.Text.TextInterface.Font.AddFontFaceToCache()
   at MS.Internal.Text.TextInterface.Font.GetFontFace()
   at System.Windows.Media.GlyphTypeface..ctor(Font font)
   at MS.Internal.FontFace.PhysicalFontFamily.GetGlyphTypeface(FontStyle style,
FontWeight weight, FontStretch stretch)
   at
MS.Internal.FontFace.PhysicalFontFamily.MS.Internal.FontFace.IFontFamily.GetType
faceMetrics(FontStyle style, FontWeight weight, FontStretch stretch)
   at System.Windows.Media.Typeface.ConstructCachedTypeface()
   at System.Windows.Media.Typeface.get_CachedTypeface()
   at
System.Windows.Media.Typeface.CheckFastPathNominalGlyphs(CharacterBufferRange
charBufferRange, Double emSize, Double scalingFactor, Double widthMax, Boolean
keepAWord, Boolean numberSubstitution, CultureInfo cultureInfo,
TextFormattingMode textFormattingMode, Boolean isSideways, Int32&
stringLengthFit)
   at
MS.Internal.TextFormatting.SimpleRun.CreateSimpleTextRun(CharacterBufferRange
charBufferRange, TextRun textRun, TextFormatterImp formatter, Int32 widthLeft,
Boolean emergencyWrap)
   at MS.Internal.TextFormatting.SimpleRun.Create(FormatSettings settings,
CharacterBufferRange charString, TextRun textRun, Int32 cp, Int32 cpFirst, Int32
runLength, Int32 widthLeft)
   at MS.Internal.TextFormatting.SimpleTextLine.Create(FormatSettings settings,
Int32 cpFirst, Int32 paragraphWidth)
   at MS.Internal.TextFormatting.TextFormatterImp.FormatLineInternal(TextSource
textSource, Int32 firstCharIndex, Int32 lineLength, Double paragraphWidth,
TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak,
TextRunCache textRunCache)
   at MS.Internal.TextFormatting.TextFormatterImp.FormatLine(TextSource
textSource, Int32 firstCharIndex, Double paragraphWidth, TextParagraphProperties
paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache)
   at System.Windows.Controls.TextBlock.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.StackPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size
constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.StackPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean
forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size
referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size
constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Window.MeasureOverrideHelper(Size constraint)
   at System.Windows.Window.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object
resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object
resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate
callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,
Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at
System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object
state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg,
IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr
lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate
callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,
Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority
priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr
wParam, IntPtr lParam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNat
iveMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32
reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)



Handling System.ArgumentException in WindowsBase.dll

$
0
0

There is a known bug in a vendor's charting package where they are not freezing their brushes, and when we go to print these controls to XPS it throws an ArgumentException originating in WindowsBase.Dll.

For now I am simply interested in catching and discarding this exception, as the charts render accurately, and it appears this exception is being thrown as a precaution.  I wrapped a try / catch around the app OnStartup contents, but this does not seem to catch the exception.

How might I go about doing this?

Add drag-able image over image

$
0
0

Hi,

In my window, i have an image element and let the users to edit the images. One of the feature i would like to do it, to add a re-size able & drag-able image over the existing image element & save the final image.

How could i allow the user to an re-size able & drag-able image over the existing image element.

<Viewbox  x:Name="cImage" Stretch="Uniform"  Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Margin="0"><Image x:Name="ViewedPhoto"   Source="IMG_0071.jpg" 
		Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Left"  Margin="0,5,0,95" ></Image></Viewbox>

Please show me an example to go. Kindly give me some ideas to proceed.

Thank you

karthik



WPF Application connect to Hardware Device

$
0
0

Hi ,

        How to Hardware devices (Pain-drive , Graphics devices  , Web-Cam) connect to WPF Application in MVVM priject  architecture. Please send me best link for interact to hardware .

    Thanks  


A.Acharya Feedback to us Develop and promote your apps in Windows Store Please remember to mark the replies as answers if they help and unmark them if they provide no help.

The calling thread must be STA, because many UI components require this

$
0
0
Hi
  I have come across an error while running the Load test, in which i have added a unit test.
  Its a WPF application. Below is the Error that i am getting 
 

  System.InvalidOperationException: The calling thread must be STA, because many UI components   require this..
View 

 at System.Windows.Input.InputManager..ctor()
   at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
   at System.Windows.Input.InputManager.get_Current()
   at System.Windows.Input.KeyboardNavigation..ctor()
   at System.Windows.FrameworkElement.EnsureFrameworkServices()
   at System.Windows.FrameworkElement..ctor()
   at System.Windows.Controls.Page..ctor()
   at MobileSalesForce.CallsPage..ctor() in D:\satya\Projects\MSForce\CallsPage.xaml.cs:line 33
   at MSForce.CallsPage_Accessor..ctor()
   at TFS_MSForce_Test.CallsPageTest.LoadCallDetailsTest() in D:\satya\Projects\MSForce\TFS_MSForce_Test\CallsPageTest.cs:line 99

   plz help me, i dont have much idea on threading

thanks
satya

 

TiffBitmapEncoder Frames Memory Leak

$
0
0
 I am trying to generate multi-frame TIFF files.  My code generates an 'Insufficient memory to continue the execution of the program.' error after about 40 frames.
        private void button1_Click(object sender, EventArgs e)  
        {  
            TiffBitmapEncoder encoder = new TiffBitmapEncoder();  
            encoder.Compression = TiffCompressOption.Ccitt4;  
            for (int i = 1; i <= 200; i++)  
            {  
                encoder.Frames.Add(MakeFrame(i));  
            }  
 
            using (Stream stream = File.Create(@"Test.tif"))  
            {  
                encoder.Save(stream);  
            }  
 
        }  
 
 
        private BitmapFrame MakeFrame(int iPage)  
        {  
            DrawingVisual drawingVisual = new DrawingVisual();  
            DrawingContext drawingContext = drawingVisual.RenderOpen();  
 
            drawingContext.DrawEllipse(Brushes.White,null,new Point(200,200),100,100);  
            drawingContext.Close();  
 
            RenderTargetBitmap bmp = new RenderTargetBitmap(2550, 3300,  
                300, 300, PixelFormats.Pbgra32);  
 
            bmp.Render(drawingVisual);  
 
            return BitmapFrame.Create(bmp);  
        } 

Does header files (as we did with C language) exist in WPF?

$
0
0

hi there,

I'm trying to avoid put all these lines in some WPF views over and over again.

I would like to put all this stuff inside a file and then just call this file.

Imports Microsoft.Office.Interop.Word Imports Microsoft.Win32 Imports System.Windows.Xps.Packaging Imports System Imports System.IO Imports System.Net Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Data Imports System.Data.SqlClient Imports System.Windows.Media Imports System.Windows.Media.Animation Imports System.Windows.Navigation Imports System.Data Imports System.Text.RegularExpressions Imports Infralution.Localization.Wpf Imports System.Globalization Imports System.Threading Imports System.Xml Imports System.Xml.Serialization Imports System.Management Imports System.DateTime Imports System.Configuration Imports System.Windows.Controls.Primitives Imports System.Collections.ObjectModel

Imports iTextSharp.text.pdf
Imports iTextSharp.text Imports Telerik.Windows Imports Telerik.Windows.Controls.GridView Imports System.Windows.Threading Imports TaskScheduler Imports GIT_CuadroMando.Procesos



Find Grid.Row and Grid.Column

$
0
0

I have a UserControl with the following pseudo XAML

<Grid>
<TextBox x:Name="EditBox1"/>

    <GroupBox>

<Grid>

<Grid> <Grid><Grid>
<TextBlock/><TextBlock/><TextBlock/>
</Grid></Grid></Grid>

</Grid>

</GroupBox>

</Grid>


What I want to do is click on the any of the TextBlock fields and have the TextBlock hide and place the TextBox in the same position as the hidden TextBlock.
Basically I want the user to be able to click on the Label and change the contents of the label. What I am having problem is how to get the current position of the clicked TextBlock and set the TextBox at that position



Here's my code behind:

       private void TextBlock_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (_currentField != null && _currentField.Visibility == Visibility.Hidden)
            {
                _currentField.Visibility = Visibility.Visible;
            }
            _currentField = (TextBlock)sender;

            EditBox1.Text = _currentField.Text;
            _currentField.Visibility = Visibility.Hidden;
            var row = _currentField.GetValue(Grid.RowProperty);

            EditBox1.SetValue(Grid.RowProperty, row);
            EditBox1.Visibility = Visibility.Visible;

            EditBox1.Focus();

            e.Handled = true;

        }


Peter

Using Global HotKeys In WPF C#

$
0
0
I have been searching High and low for a solution to control my program from anyware in windows with multiple hot Keys.

Rogelio Rios


Add custom tooltips and intellisense to XAML and CS files

$
0
0

Hi,

I added a bit of multi-language functionality to my project and everything works fine.

Yet it's not very coder-friendly.

What I'm trying to do now (in Visual Studio 2010 or later) is to extend or add a language service that simply overrides the default tooltip and displays specific info on the key. Depending, of course, on whether the string is actually a parameter to my "Translate" method.

I have such a neat picture, too, to explain what I need to do, but I'm not allowed to post one yet :(

So let me try it like this :

textbox.Text = MyTranslationClass.Translate("TranslationKey_SomeText");

When the cursor enters a string VS intellisense usually displays the tooltip "class System.String". But what I want it to do is a) recognize that this string is part of my "MyTranslationClass.Translate" method, then b) look it up in my database (just like when the app is running) and change the tooltip to "key: TranslationKey_SomeText, value: Hello, world".

It doesn't need to do anything else.

It should also work on markup extensions in XAML, though.

e.g. Text="{TranslateConverter:Translate TranslationKey_SomeText}"

All I found on google was how to implement one's own coding language. That'd be total overkill and I don't know where to start. Plus, the standard VS intellisense should not be affected either.

Any hints on how to achieve this?

TIA


ClickOnce fails to run on Citrix Access Gateway

$
0
0

Does it possible to had ClickOnce application deployed behind Citrix Access Gateway?

We use Default.aspx with IFRAME that puts XBAP inside. 

We found this problem :

- First XBAP request will pass Citrix cookies to the server

- Second XBAP request will not had any Citrix cookies, thus it will redirects to Citrix login page.

Our search on this matter is that this is known issue with ClickOnce installation on proxy server.

My question is, is this somehow fixed or any workaround with this?

Thanks and Regards

WPF FlowDirection

$
0
0

Hi,

I'm having a problem when changing a flow direction in  a usercontrol by code, it changes all controls flowdirection.

How do i avoid some of thouse controls of changing flowdirection, maintaining allways LTR flowdirection.

Best Regards

WPF performence problems with any CPUs?

$
0
0

Hi!

I have a small WPF Sample with 23 TextBoxes...

On some CPUs comes a hanger (Leak?) if i make a refresh of the fields...

here is the XAML Code:

<Window x:Class="Win7Hanger.MainWindow" 
        Title="Win7Hanger " Height="568" Width="703" MinHeight="568" MinWidth="703"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Icon="/Win7Hanger;component/HF-Icon.ico"><Viewbox Stretch="Fill" StretchDirection="Both" VerticalAlignment ="Top"><Canvas Height="529" Width="681" 
				Background="LightYellow" 
				Name="MainCanvas" 
				HorizontalAlignment="Left" 
				VerticalAlignment="Top"><Label Canvas.Left="597" Canvas.Top="460" Height="29" Name="labelOkJN" Content="Ok J/N:" FontWeight="Bold" FontSize="14" FontFamily="Courier New" Foreground = "Black" VerticalContentAlignment="Top" /><TextBox Canvas.Left="0" Canvas.Top="102" Height="21" Width="683" Name="A_ROLLZ_1" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_1, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="122" Height="21" Width="683" Name="A_ROLLZ_2" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_2, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="142" Height="21" Width="683" Name="A_ROLLZ_3" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_3, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="162" Height="21" Width="683" Name="A_ROLLZ_4" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_4, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="182" Height="21" Width="683" Name="A_ROLLZ_5" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_5, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="202" Height="21" Width="683" Name="A_ROLLZ_6" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_6, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="222" Height="21" Width="683" Name="A_ROLLZ_7" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_7, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="242" Height="21" Width="683" Name="A_ROLLZ_8" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_8, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="262" Height="21" Width="683" Name="A_ROLLZ_9" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_9, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="282" Height="21" Width="683" Name="A_ROLLZ_10" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_10, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="302" Height="21" Width="683" Name="A_ROLLZ_11" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_11, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="322" Height="21" Width="683" Name="A_ROLLZ_12" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_12, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="342" Height="21" Width="683" Name="A_ROLLZ_13" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_13, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="362" Height="21" Width="683" Name="A_ROLLZ_14" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_14, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="382" Height="21" Width="683" Name="A_ROLLZ_15" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_15, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="402" Height="21" Width="683" Name="A_ROLLZ_16" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_16, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="422" Height="21" Width="683" Name="A_ROLLZ_17" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_17, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="0" Canvas.Top="442" Height="21" Width="683" Name="A_ROLLZ_18" FontWeight="Bold" FontSize="14" IsReadOnly="True" Focusable="False"  FontFamily="Courier New" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="LightYellow"  Foreground="Black"
		    Text="{Binding Prop_A_ROLLZ_18, Mode=TwoWay}"></TextBox><TextBox Canvas.Left="142" Canvas.Top="462" Height="21" Width="430" Name="A_HINW" FontWeight="Bold" FontSize="14" FontFamily="Courier New" TextAlignment="Left" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="White" Foreground="#FFD83737"
    			Text="{Binding Path=Prop_A_HINW}" 
	    		GotFocus="TextBox_GotFocus" 
		    	PreviewKeyDown="TextBox_PreviewKeyDown"></TextBox><TextBox Canvas.Left="664" Canvas.Top="462" Height="21" Width="18" Name="E_OK" FontWeight="Bold" FontSize="14" FontFamily="Courier New" TextAlignment="Left" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Background="White" Foreground="Black"
    			Text="{Binding Path=Prop_E_OK}" 
    			GotFocus="TextBox_GotFocus" 
    			PreviewKeyDown="TextBox_PreviewKeyDown"></TextBox><TextBox Canvas.Left="79" Canvas.Top="77" Height="21" Name="textBoxZeit" Width="70" Focusable="False" /><Label Canvas.Left="11" Canvas.Top="74" Content="Füllzeit:" Height="28" Name="labelZeit" /><Label Canvas.Left="156" Canvas.Top="75" Content="ms" Height="28" Name="labelEinheit" /><Button Canvas.Left="194" Canvas.Top="77" Content="Reset" Height="21" Name="buttonReset" Width="75" Click="buttonReset_Click" Focusable="False" /><Label Canvas.Left="7" Canvas.Top="0" Content="TAB-Taste gedrückt halten, um die TextBoxen laufend zu beschreiben. Die max. Füllzeit einer Aktualisierung wird ausgewiesen" Height="28" Name="labelAnleitung" /><Label Canvas.Left="8" Canvas.Top="51" Content="CPU-Kern:" Height="28" Name="labelProzessor" /><TextBox Canvas.Left="100" Canvas.Top="53" Focusable="False" Height="23" Name="textBoxProzessor" Width="26" /><Button Canvas.Left="75" Canvas.Top="53" Content="-" Focusable="False" Height="23" Name="buttonMinus" Width="25" Click="buttonMinus_Click" /><Button Canvas.Left="127" Canvas.Top="53" Content="+" Focusable="False" Height="23" Name="buttonPlus" Width="25" Click="buttonPlus_Click" /><Label Canvas.Left="155" Canvas.Top="52" Content="Label" Height="28" Name="labelCpu" /><Label Canvas.Left="8" Canvas.Top="24" Content="Sobald der Prozess auf mehreren CPU Kernen läuft, hängt die Aktualisierung gelegentlich. ESC beendet die Anwendung." Height="28" Name="labelHint" /></Canvas></Viewbox></Window>

here is the C# Code for the XAML...

using System;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Diagnostics;
namespace Win7Hanger
{
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        #region Members

        public event PropertyChangedEventHandler PropertyChanged;
        private Random rnd = new Random((int)DateTime.Now.Ticks);
        private long maxZeit = 0;
        private int processor = 3;
    
        #endregion

        // Jede Textbox ist über Binding mit einer Property verbunden
        #region PropertyBinding

        private string _a_rollz_1;
        public string Prop_A_ROLLZ_1
        {
            get
            {
                return _a_rollz_1;
            }

            set
            {
                if (_a_rollz_1 != value)
                {
                    _a_rollz_1 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_1");
                }
            }
        }

        private string _a_rollz_2;
        public string Prop_A_ROLLZ_2
        {
            get
            {
                return _a_rollz_2;
            }

            set
            {
                if (_a_rollz_2 != value)
                {
                    _a_rollz_2 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_2");
                }
            }
        }

        private string _a_rollz_3;
        public string Prop_A_ROLLZ_3
        {
            get
            {
                return _a_rollz_3;
            }

            set
            {
                if (_a_rollz_3 != value)
                {
                    _a_rollz_3 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_3");
                }
            }
        }

        private string _a_rollz_4;
        public string Prop_A_ROLLZ_4
        {
            get
            {
                return _a_rollz_4;
            }

            set
            {
                if (_a_rollz_4 != value)
                {
                    _a_rollz_4 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_4");
                }
            }
        }

        private string _a_rollz_5;
        public string Prop_A_ROLLZ_5
        {
            get
            {
                return _a_rollz_5;
            }

            set
            {
                if (_a_rollz_5 != value)
                {
                    _a_rollz_5 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_5");
                }
            }
        }

        private string _a_rollz_6;
        public string Prop_A_ROLLZ_6
        {
            get
            {
                return _a_rollz_6;
            }

            set
            {
                if (_a_rollz_6 != value)
                {
                    _a_rollz_6 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_6");
                }
            }
        }

        private string _a_rollz_7;
        public string Prop_A_ROLLZ_7
        {
            get
            {
                return _a_rollz_7;
            }

            set
            {
                if (_a_rollz_7 != value)
                {
                    _a_rollz_7 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_7");
                }
            }
        }

        private string _a_rollz_8;
        public string Prop_A_ROLLZ_8
        {
            get
            {
                return _a_rollz_8;
            }

            set
            {
                if (_a_rollz_8 != value)
                {
                    _a_rollz_8 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_8");
                }
            }
        }

        private string _a_rollz_9;
        public string Prop_A_ROLLZ_9
        {
            get
            {
                return _a_rollz_9;
            }

            set
            {
                if (_a_rollz_9 != value)
                {
                    _a_rollz_9 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_9");
                }
            }
        }

        private string _a_rollz_10;
        public string Prop_A_ROLLZ_10
        {
            get
            {
                return _a_rollz_10;
            }

            set
            {
                if (_a_rollz_10 != value)
                {
                    _a_rollz_10 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_10");
                }
            }
        }

        private string _a_rollz_11;
        public string Prop_A_ROLLZ_11
        {
            get
            {
                return _a_rollz_11;
            }

            set
            {
                if (_a_rollz_11 != value)
                {
                    _a_rollz_11 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_11");
                }
            }
        }

        private string _a_rollz_12;
        public string Prop_A_ROLLZ_12
        {
            get
            {
                return _a_rollz_12;
            }

            set
            {
                if (_a_rollz_12 != value)
                {
                    _a_rollz_12 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_12");
                }
            }
        }

        private string _a_rollz_13;
        public string Prop_A_ROLLZ_13
        {
            get
            {
                return _a_rollz_13;
            }

            set
            {
                if (_a_rollz_13 != value)
                {
                    _a_rollz_13 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_13");
                }
            }
        }

        private string _a_rollz_14;
        public string Prop_A_ROLLZ_14
        {
            get
            {
                return _a_rollz_14;
            }

            set
            {
                if (_a_rollz_14 != value)
                {
                    _a_rollz_14 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_14");
                }
            }
        }

        private string _a_rollz_15;
        public string Prop_A_ROLLZ_15
        {
            get
            {
                return _a_rollz_15;
            }

            set
            {
                if (_a_rollz_15 != value)
                {
                    _a_rollz_15 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_15");
                }
            }
        }

        private string _a_rollz_16;
        public string Prop_A_ROLLZ_16
        {
            get
            {
                return _a_rollz_16;
            }

            set
            {
                if (_a_rollz_16 != value)
                {
                    _a_rollz_16 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_16");
                }
            }
        }

        private string _a_rollz_17;
        public string Prop_A_ROLLZ_17
        {
            get
            {
                return _a_rollz_17;
            }

            set
            {
                if (_a_rollz_17 != value)
                {
                    _a_rollz_17 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_17");
                }
            }
        }

        private string _a_rollz_18;
        public string Prop_A_ROLLZ_18
        {
            get
            {
                return _a_rollz_18;
            }

            set
            {
                if (_a_rollz_18 != value)
                {
                    _a_rollz_18 = value;
                    this.OnPropertyChanged("Prop_A_ROLLZ_18");
                }
            }
        }

        private string _a_hinw;
        public string Prop_A_HINW
        {
            get
            {
                return _a_hinw;
            }

            set
            {
                if (_a_hinw != value)
                {
                    _a_hinw = value;
                    this.OnPropertyChanged("Prop_A_HINW");
                }
            }
        }

        private string _e_ok;
        public string Prop_E_OK
        {
            get
            {
                return _e_ok;
            }

            set
            {
                if (_e_ok != value)
                {
                    _e_ok = value;
                    this.OnPropertyChanged("Prop_E_OK");
                }
            }
        }

        // OnPropertyChanged
        void OnPropertyChanged(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }

        #endregion

        #region Konstruktor
        
        // Konstruktor
        public MainWindow()
        {
            // set affinity of current thread to the given cpuID
            Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(3);

            DataContext = this;
            InitializeComponent();

            ShowProcessor();
        }
        
        #endregion

        #region GUI-Handling

        // Bei Fokussierung des Feldes den gesamten Text markieren
        private void TextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            (sender as TextBox).SelectAll();
        }

        // Variable für Maximaldauer zurücksetzen
        private void buttonReset_Click(object sender, RoutedEventArgs e)
        {
            maxZeit = 0;
            textBoxZeit.Text = String.Empty;
        }

        // CPU Kern umschalten
        private void buttonMinus_Click(object sender, RoutedEventArgs e)
        {
            if (processor > 1)
            {
                processor--;
            }
            else
            {
                processor = 3;
            }

            ShowProcessor();
        }

        // CPU Kern umschalten
        private void buttonPlus_Click(object sender, RoutedEventArgs e)
        {
            if (processor < 3)
            {
                processor++;
            }
            else
            {
                processor = 1;
            }

            ShowProcessor();
        }

        #endregion

        #region Tastaturhandling

        // Tastatureingabehandling
        private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                // ESC = Programm beenden
                case Key.Escape:
                    this.Close();
                    break;

                default:
                    FillData();
                    break;
            }
        }

        #endregion

        #region Helpers

        // Textboxen mit zufälligem Inhalt füllen
        private void FillData()
        {
            long start = DateTime.Now.Ticks;
            Mouse.OverrideCursor = Cursors.Wait;

            Prop_A_ROLLZ_1 = RandomText(80);
            Prop_A_ROLLZ_2 = RandomText(80);
            Prop_A_ROLLZ_3 = RandomText(80);
            Prop_A_ROLLZ_4 = RandomText(80);
            Prop_A_ROLLZ_5 = RandomText(80);
            Prop_A_ROLLZ_6 = RandomText(80);
            Prop_A_ROLLZ_7 = RandomText(80);
            Prop_A_ROLLZ_8 = RandomText(80);
            Prop_A_ROLLZ_9 = RandomText(80);
            Prop_A_ROLLZ_10 = RandomText(80);
            Prop_A_ROLLZ_11 = RandomText(80);
            Prop_A_ROLLZ_12 = RandomText(80);
            Prop_A_ROLLZ_13 = RandomText(80);
            Prop_A_ROLLZ_14 = RandomText(80);
            Prop_A_ROLLZ_15 = RandomText(80);
            Prop_A_ROLLZ_16 = RandomText(80);
            Prop_A_ROLLZ_17 = RandomText(80);
            Prop_A_ROLLZ_18 = RandomText(80);
            Prop_A_HINW = RandomText(30);
            Prop_E_OK = "J";

            long dauer = DateTime.Now.Ticks - start;
            if (dauer > maxZeit)
            {
                maxZeit = dauer;
                textBoxZeit.Text = TimeSpan.FromTicks(maxZeit).TotalMilliseconds.ToString();
            }
            Mouse.OverrideCursor = null;
        }

        // String mit zufälligen Zeichen der angegebenen Länge füllen
        private string RandomText(int length)
        {
            StringBuilder retVal = new StringBuilder();

            for (int i = 0; i < length; i++)
            {
                retVal.Append(rnd.Next(32, 85));
            }

            return retVal.ToString();
        }

        // Anzeige des ausgewählten CPU Kerns
        private void ShowProcessor()
        {
            // gemessene Zeit zurücksetzen
            maxZeit = 0;
            textBoxZeit.Text = String.Empty;

            // Prozessorauswahl anzeigen
            textBoxProzessor.Text = processor.ToString();
            switch (processor)
            {
                case 1:
                    labelCpu.Content = "CPU 1";
                    break;
                case 2:
                    labelCpu.Content = "CPU 2";
                    break;
                case 3:
                    labelCpu.Content = "CPU 1 + 2";
                    break;
            }
            Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(processor);
        }

        #endregion
    }
}

I test it with:
1 = CPU1
2 = CPU2
3 = CPU1 + CPU2

Under 3 the Hanger (Leak) is extream...
You can test it if you let the program running and use "3" for "CPU 1 + 2" and then press permanent the TAB-Key...

Here are teh results from my Tests:
Intel I3 + Windows 7 64, NO Problem
Intel I5 + Windows 7 64, "3" have a Problem
Intel I7 920 + Windows 7 64 Bit, NO Problem
Intel I7 980 + Windows 7 64 Bit, NO Problem
MS-Virtual PC + Window 7 32 Bit, NO Problem

Have anyone an idea?

Best Regards

Bernd

How to load and save an listbox?

$
0
0
Hello everyone, i'm making an sort of trackingprogram with an listbox, but i don't know how to save the listbox in my.settings or as an .TXT file. I also want to reOpen the file when i start the program at an later time. Can anybody help me please?

(I work with Visual Basic 2013)

"Unable to cast object of type 'System.Windows.Controls.TextBlock' to type 'System.Windows.Controls.Control'." While assigning stackpannel childrens(Controls) in to the Control i am getting this error

$
0
0

Hi,

While assigning stackpannel childrens(Controls) in to the Control i am getting this error like "Unable to cast object of type 'System.Windows.Controls.TextBlock' to type 'System.Windows.Controls.Control'.

If i use "Var" instead of "Control" i am getting compile time  error for (getvalue and setvalues).

Stackpannel having Textblock,Combobox,lable etc. as shown bellow

 foreach (VirtualizingStackPanel sp in pnlVolumeDetails.Children)
                {
                    foreach (Control ctrl in sp.Children)
                    {
                        if (ctrl is TextBox)
                        {
                            if (IsNumeric(ctrl.GetValue(TextBox.TextProperty)))
                            {

                            }
                            else
                            {
                                Utils.ShowErr

Please help me.........

Regards,

Ranjith


Ranjithkumar

Viewing all 18858 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>