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

How to display windows like this with some UI controls inside


Custom Panel Virtualization

$
0
0

Hi guys,

i am working on a custom panel that supports ui virtualization. I was able to write a piece of code that allowed me to scroll up and down but now i realized that i cannot recall a selected state of an item because i was removing items that were below or above the offset.Y + viewpoint.Height.. As example if i select item with index 100 and then i scroll to the end to index 999, the itemContainer of 100 will be removed and therefore when i scroll back to 100, i see a freshy created container which isnt selected (i lost selection).

How do i store already created but not at the moment visible items and their conditions/states?

It has to be something with generator.Remove and UIElementCollection.AddChild but i have no idea how to code the desized effect.

Any help?

The Generic.Xaml file in a VB.NET solution vs. a C# solution

$
0
0
We went to VS Live in Orlando, in December 2012. There Billy Hollis did an excellent presentation on WPF and navigation. We're trying to adapt his example app, which he did in VB.NET 2012, to C# 2012. He has a Generic.Xaml file in a folder named Themes in a project called NavShellCotrols. We have the same file (identical, in fact) in the same folder, in a project by the same name. When we run his example project in VS 2012, it works fine. But when we run our project, in VS 2012, it can't find the template named "HeaderContent" nor the one named "MainContent". I'm wondering if it has anything to do with the fact that they're different languages (VB.NET vs. C#)? I seem to remember that in VB.NET any files within folders in a project are treated as if they were all at the root level of the project; whereas with C# any files in folders in a project are treated differently. Not exactly like they're in different projects, but different nevertheless. Could that be why we're having difficulty?

Rod

string format for percentage not working correctly

$
0
0

Hi ,

using string format for percentage but , my text show in correct value even if i enter correct value.

when i enter 2.00% then become red border for textbox. below code. tell me what wrong in code.

 Data objDat = new Data();
        public Window1()
        {
            InitializeComponent();
            this.DataContext = objDat;
        }
public class Data : INotifyPropertyChanged
    {
        public string Name {get; set;}
        public decimal amt { get; set; }
        public event PropertyChangedEventHandler PropertyChanged;
        public decimal Amt
        {
            get { return amt; }
            set
            {
                amt = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Amt"));
            }
        }
    }<Grid><Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="55,94,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click"/><TextBox Height="23" Text="{Binding Name}" HorizontalAlignment="Left" Margin="74,141,0,0" Name="textBox1" VerticalAlignment="Top" Width="120"  PreviewTextInput="textBox1_PreviewTextInput" FlowDirection="RightToLeft" KeyDown="textBox1_KeyDown" /><TextBox Height="23"  Text="{Binding Amt, UpdateSourceTrigger=PropertyChanged,StringFormat={}{0:N2}%,
                                                    Mode=TwoWay}"    HorizontalAlignment="Left" Margin="78,195,0,0"   Name="textBox2" VerticalAlignment="Top" Width="120" ></TextBox><Button Content="New" Height="23" HorizontalAlignment="Left" Margin="149,45,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" /></Grid>


Ashok


Streaming Media from Media Server (client application)

Windows 8: System.Windows.Input.InputLanguageManager.Current.InputLanguageChanged not firing

$
0
0

System.Windows.Input.InputLanguageManager.Current.InputLanguageChanged event does not fire in windows 8 but System.Windows.Forms.Form.InputLanguageChanged does.

Is this a WPF bug? Or am I doing something wrong?

Thanks.


Vladimir Khil


[C#] Need a little help whilst making a Custom Window

$
0
0

Hello, I'm trying to make a Custom Window. The idea I like is similar to the design of VS2012.

I am using XAML with a bit of C# for this, and I'm struggling. So far I've created a grey window with a blue border. I have been trying to implement the DragMove() feature ... but I am failing and not in a good way!

MainWindow.xaml

<Window x:Class="CustomWindowRetry.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"
        Style="{DynamicResource MainWindow}" WindowStyle="None" AllowsTransparency="True"><Grid></Grid></Window>

App.xaml

<Application x:Class="CustomWindowRetry.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"><Application.Resources><Style x:Key="MainWindow" TargetType="{x:Type Window}"><Setter Property="Background" Value="LightGray" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Window}"><Grid><Border x:Name="MainBorder"
                                    BorderBrush="#FF017ACC"
                                    BorderThickness="1"
                                    Background="#FFEFEFF2"
                                    Padding="6, 0, 6, 6"
                                    MouseDown="MainBorder_MouseDown"><ContentPresenter /></Border></Grid></ControlTemplate></Setter.Value></Setter></Style></Application.Resources></Application>

App.xaml.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace CustomWindowRetry
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private void MainBorder_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
            {
                ((Window)sender).DragMove();
            }
        }
    }
}

The idea is that I am able to drag the window, of course this styling is limited to one window. So I'd liek to make it so I can open multi windows (if I wish to do so) and control each one separately. My error is that it cannot convert the Border to a Window control, which I do understand - I'm just not sure how to go about it...

This thread will get quite large, as I work through the window process. Saves me creating a new thread for each problem that I get relating to the same topic.

WPF Ribbonmenu bind IsEnabled to HasEnabled Child

$
0
0

Hi,

I'm having some difficulties with the microsoft Ribbontoolkit for WPF.

I have a RibbonMenu in my ribbon:

<ribbon:RibbonMenuButton Label="{x:Static p:Resources.Convert}" SmallImageSource="{StaticResource ConvertSmallImageSource}" LargeImageSource="{StaticResource ConvertImageSource}" ><ribbon:RibbonMenuItem Header="{x:Static p:Resources.ToInvoice}" IsEnabled="{Binding ConvertToInvoiceCommand, Converter={x:Static c:CommandToEnabledConverter.Default}}" Command="{Binding ConvertToInvoiceCommand}" /><ribbon:RibbonMenuItem Header="{x:Static p:Resources.ToPdf}" IsEnabled="{Binding ConvertToPdfCommand, Converter={x:Static c:CommandToEnabledConverter.Default}}" Command="{Binding ConvertToPdfCommand}" /></ribbon:RibbonMenuButton>

I was wondering if it is possible to enable/disable my RibbonMenuButton on whether there is a RibbonMenuItem enabled.

Is it possible to do this with binding?

Also the Commands I'm giving are basically ICommands or DelegateCommands.


Validate a command to allow user only to enter one row into database

$
0
0

Hi guys.

I am creating an application that allows users to enter in their Organisation details into the database using MVVM and EF. I have a User Control which allows a user to enter a set of Organisation details into the database.

Within this application, the view-model contains properties, commands and CRUD operations.

What I want to achieve is to allow the user using this application to enter their details, but once a row has been entered into the database, disable the command altogether or throw an exception stating that one row has been added.

I have a tab control for the user to enter their details and then data grid for them to visually see the details been added. 

Is this possible to achieve? How would this be done? Iterate through the rows and then find that row?

Here are my code snippets that my relevant; 

View-Model;

        private ICommand showAddCommand;
        public ICommand ShowAddCommand
        {
            get
            {
                if (this.showAddCommand == null)
                {
                    this.showAddCommand = new RelayCommand(this.SaveFormExecute, this.SaveFormCanExecute);
                }

                return this.showAddCommand;
            }
        }

        private bool SaveFormCanExecute()
        {
                return true;
        }

        private void SaveFormExecute()
        {
            InsertOrganisationTypeDetail();
        }

XAML;

<Button Content="Save" Grid.Row="9" Name="btnSave" VerticalAlignment="Top" Grid.Column="1" Width="75"
            Command="{Binding ShowAddCommand}" />

Many thanks,

Greg.



How to change the text in textbox without letting the TextChanged Event to fire?

$
0
0

Dear all

I made a numeric textbox that when user insert the amount it will automatically add comma when the textbox lose it's focus. Everything works well except I figure out that I have a problem and after long checking I realize it is coming from adding comma.

In the codes that I use this numeric textbox I mostly use the event TextChanged. Now the problem is that when system add comma this even will fire again and it will change everything in my code. Now my question is that how can I stop TextChange Event from firing when I want to add comma.

Simply I just need to turn off TextChange Event add comma then turn it on again.

Is it possible?

I am coding using VB.Net and WPF

Thank you so much


Nothing is Impossible

Not able to open Windows context menu in WPF application.

$
0
0

Hi,

        I am working on WPF Application using c sharp.I want to display Windows My Computer Context Menu  in my custom window where I have all contents of My Computer. I am able to open context menu for files and folders but not for blank space.How can I open Windows context menu in my custom window on blank space.Please help me out.

Thanks

Swati

Exception when printing XPS-Document

$
0
0

Hallo,

with our application document will be printed via the XpsDocumentWriter.

Almost everytime the print works without any problems.

But from time to time the following error occurs:

PrintTicket provider failed to convert DEVMODE to PrintTicket.Win32 error:-2147467259
   at MS.Internal.Printing.Configuration.PTProvider.ConvertDevModeToPrintTicket(Byte[] devMode,PrintTicketScope scope)
   at System.Printing.Interop.PrintTicketConverter.InternalConvertDevModeToPrintTicket(PTProviderBase provider,Byte[] devMode,PrintTicketScope scope)
   at System.Printing.PrintTicketManager.ConvertDevModeToPrintTicket(Byte[] devMode)
   at System.Printing.PrintQueue.get_UserPrintTicket()
   at System.Windows.Xps.Serialization.NgcPrintTicketManager.ConstructPrintTicketTree(XpsSerializationPrintTicketRequiredEventArgs args)
   at System.Windows.Xps.Serialization.NgcSerializationManagerAsync.OnNGCSerializationPrintTicketRequired(Object operationState)
   at System.Windows.Xps.Serialization.NgcSerializationManagerAsync.SaveAsXaml(Object serializedObject)
   at System.Windows.Xps.XpsDocumentWriter.WriteAsync(DocumentPaginator documentPaginator,PrintTicket printTicket)
   at Willis.Base.Pdf.PagePrintMailControl.simpleButtonPrint_Click(Object sender,EventArgs e)

What could be the reason for this?

Printing one document on day a on the same printer by the same user can result in the error but on day b the same document on the same printer by the same user can be printed without an error, what is pretty strange.

Thanks for your help.

How to catch an OutOfMemoryException while XpsDocumentWriter.WriteAsync() ?

$
0
0

Hi,

I want to print some XPS documents.

Sometimes (if the document is pretty large) an OutOfMemoryException is thrown.

Unfortunately the whole application crushes in that case.

I want to catch such exceptions and display a MessageBox.

How to do that?

Thanks for your help,

Jan

Scrollbar of tab page in tab control moves unexpectedly clicking on the grid in windows form

$
0
0
I am currently working in a windows application. Which contains 4-5 tabs in a form within those tab pages i need to put more than 6 grids so it goes out of the tab page due to which i need to enable the scrolling of that tab page.

Now the issue is that on clicking any of the row/cell of the grids the page gets flickered and the scrolling position changes for the tab page which causes irritating behavior and i am unable to do anything on the page.

Please help me out in this regard.


Thanks & Regards Smruti Ranjan Sahoo

Weird performance problem with Shapes.Path

$
0
0

Hi,

I got a weird performance issue with the System.Windows.Shapes.Path class.

I have a loop creating about 40,000 paths into a Canvas. There are one or two handfuls of different Brushes used for the objects.

When I create a new SolidColorBrush for each iteration, the loop takes about 3.5 seconds:

Brush brStroke = null;
for (uint index = 0; index < count; index++)
   {
   System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();

   path.Data = GetPathData();

   brStroke = new SolidColorBrush(GetColor(index));

   path.Stroke = brStroke;
   path.StrokeThickness = thickness;
   canvas.Children.Add(path);
   }

I thought I could speed this up a bit by creating a dictionary for the brushes and cache them. But this version of the loop takes 90 seconds!

Dictionary<ushort, Brush> brushes = new Dictionary<ushort,Brush>();
Brush brStroke = null;
for (uint index = 0; index < count; index++)
   {
   System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();

   path.Data = GetPathData();

   ushort gt = GetColorTableIndex(index);
   if (brushes.ContainsKey(gt))
      brStroke = brushes[gt];
   else
      {
      brStroke = new SolidColorBrush(GetColor(index));
      brushes.Add(gt, brStroke);
      }

   path.Stroke = brStroke;
   path.StrokeThickness = thickness;
   canvas.Children.Add(path);
   }

Why that?

Does anybody have an idea?

Thanks,

Thomas

 


How to generate dynamically animate Polyline and move Rectangle with collection of List?

$
0
0

Hi,

I'm new to WPF. In my college i learn to do animation in WPF by coding in XAML file. I wan't to do some experiment to create a dinamic animation of rectangle moving by coordinates collected in List<Point> with a polyline animated drawn along with the movement of rectangle. If you can't understand what i'm saying just imagine old Windows screen saver where the pipe is animated (3D). Now imagine that it's animated in WPF but just with polyline (2D) and on the tip of the animated polyline theres a rectangle animated too. I've been searching through the internet for hours and didn't find any answer. Maybe my keyword is wrong due to lack of WPF tag information.

Thanks for your help. Cheers.

Sorry for my bad english.

Binding with GetValue(Grid.DataContextProperty)

$
0
0

Hi, i'm learning data binding. And i don't know if that is good way for it by i tried this below and get error that "get dose not exist in current context".

Why ?

//myclass
namespace DataBinding
{
    class Driver
    {
        private string Name;
        public string name
        {
            get
            {
                return this.Name;
            }
            set
            {
                this.Name = value;
            }
        }

        public Driver()
        {
            this.name = "Test";
          //  this.InitializeEvent();
        }

        public void ResetName(string name)
        {
            this.Name = "";
        }

//mainwindows cs
namespace DataBinding
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
			Driver myDriver
			{
				get
				{
                    return this.MainGrid.GetValue(Grid.DataContextProperty) as Driver;
				}
			}
            InitializeComponent();
        }

        private void btClear_Click(object sender, RoutedEventArgs e)
        {
         
        }
    }
}
// xaml 
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DataBinding" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="DataBinding.MainWindow"
        Title="MainWindow" Height="350" Width="525"><Window.Resources><local:Driver x:Key="DriverDataSource" d:IsDataSource="True"/></Window.Resources><Grid x:Name="MainGrid" DataContext="{Binding Mode=OneWay, Source={StaticResource DriverDataSource}}"><TextBlock HorizontalAlignment="Left" Height="32" Margin="27,20,0,0" TextWrapping="Wrap" Text="{Binding name, Mode=TwoWay}" VerticalAlignment="Top" Width="186"/><Button x:Name="btClear" Content="Clear" HorizontalAlignment="Left" Height="25" Margin="354,262,0,0" VerticalAlignment="Top" Width="114" Click="btClear_Click"/></Grid></Window>

Image processing in .NET

$
0
0

Hi

I need to perform image processing operations of changing brightness, sharpness and contrast. I am working with a WPF application.

Is there simple way of achieving this in .NET.

Are there inbuilt classes which can help.

Regards

JC

How to save an image to hd from following startpoint

$
0
0

this is the code i use:

image.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icons_imageres[0].Handle, new System.Windows.Int32Rect(0, 0, 30, 32), BitmapSizeOptions.FromEmptyOptions());          

i have three options to startwith my needing, from out of an ion.Handle, or a BitmapSource, or the Source-Property of an image.

Actually, i need a way to save from one of this three kinds of an icon, an in´mage to hd,

Is there any help???

My click event does not get current listview data when I sort the table on screen

$
0
0

I have a listview with a gridview inside it it. On screen I have 4 columns of data that can be sorted on screen by clicking the column header. When I create a click event to get the data from the sorted listview my data doesn't come back to me in the re sorted way if I have resorted it, it comes to me as if I hadn't resorted at all.

 private void copyData_Click(object sender, RoutedEventArgs e)
        {

            StringBuilder clipBoardData = new StringBuilder();

            if (historyList.ItemsSource == null)
            {
                return string.Empty;
            }

            foreach (NumericHistory historyItem in historyList.ItemsSource)
            {
                clipBoardData.Append(string.Format(
                "\t{0}\t{1}\t{2}\t{3}\t{4}",
                historyItem.HistoryDate.ToShortDateString(),
                historyItem.HistoryValue.ToString(),
                historyItem.ValueChange.ToString(),
                historyItem.PercentChange.ToString(),
                Environment.NewLine));
            }


chuckdawit


Viewing all 18858 articles
Browse latest View live


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