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

WPF performance issue.

$
0
0

Hi,

Working on a 3D engine for my company where the UI is done in WPF I noticed performance loss in some specific condition. Using the profiler I saw that a method of the Windows Presentation Framework took most of the time in the UI thread whereas our own code was mostly constant in time.

The method is MS.Internal.Data.DataBindEngine.CleanupOperation(System.Object) in PresentationFramework.ni.dll. Moreover, I saw that when the performance loss occurs the garbage collector run more often and for longer periods.

I have the strange feeling that the two are related in a way.

Could you tell me what what does the DataBindEngine.CleanupOperation method, in what condition it run and why it is taking so much time. Plus, can you give me where to look to find out why the garbage collector run so often ?

Thanks,

cviot


PageFunction Using

$
0
0

Hello 

In order to  implement the  "Back and Forward" features in my WPF application, I have followed this article.

http://paulstovell.com/blog/wpf-navigation

but I'm stuck on PageFunction using .

<PageFunction
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    x:Class="PageBasedApplication.PageFunction"
    x:TypeArguments="sys:Object"
    Title="PageFunction"  ><Grid><... /></Grid></PageFunction>
 public partial class PageFunction : PageFunction<Object>
    {
        public PageFunction()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {

        }


    }

i am getting this Error 

PageFunction is not supported in a Windows Presentation Foundation (WPF) project.

Thanks for your help

Up and Down Key Functionality for the Custimzed DataGridTemplate Column in DataGrid WPF

$
0
0
Hello Freinds,

Handling Up and Down Arrow keys in customized DataGridTemplateColumn and Focus on particulat control index of 
previous Cell. Kindly suggest

I have Customized column in a Grid, I mean i hv added some controls inside 
Header template and CellTemplate of DataTemplate column of a datagrid

<DataGrid >
        <DataGrid.Columns>
            <DataGridTemplateColumn Header="test1"  Visibility="{Binding MainVisi}">
                <DataGridTemplateColumn.HeaderTemplate>
                    <StackPanel Grid.Row="1" Orientation="Horizontal">
                        <TextBlock Text="{Binding temp1}" Visibility="{Binding Vis1}" ></TextBlock>
                        <TextBlock Text="{Binding temp2}" Visibility="{Binding vis2}" ></TextBlock>

 <TextBlock Text="{Binding temp3}" Visibility="{Binding vis3}" ></TextBlock>                     </StackPanel>
                </DataGridTemplateColumn.HeaderTemplate>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Border Margin="0">

                            <StackPanel Grid.Row="1" Orientation="Horizontal">
                                <TextBox Text="{Binding tempv1}" Visibility="{Binding Vis1}" Template="{StaticResource temp1}"></TextBox>
                                <TextBox Text="{Binding tempv2}" Visibility="{Binding vis2}" Template="{StaticResource temp2}"></TextBox>

 <TextBox Text="{Binding tempv3}" Visibility="{Binding vis3}" Template="{StaticResource temp2}"></TextBox>                             </StackPanel>
                        </Border>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>



Hiding address bar in Internet Explorer

$
0
0

I am trying to open Internet explorer in my WPF application.

I am referencing the Shdocvw.dll to open IE.But I am unable disable the address bar.And I can Hide the address bar.

Main issue is whenever I pressed F11 or F12 the hidden address bar is coming back.

Sample code

 var IE = new SHDocVw.InternetExplorer();

IE .ToolBar = 0;


 IE .MenuBar = false;
 IE .AddressBar = false;
 IE .Resizable = true;
 IE .StatusBar = false;
 IE .Visible = true;


 IE.Navigate2("xyz.com");

Please help on this issue

[WPF] MouseEnter event: How to get a sender?

$
0
0

Goal: To get Rectangle as sender.

Problem: It gets Grid as sender.

Question: How to get Rectangle as sender?

Note: Applying MouseEnter individually to Rectangle works, but it is not what I need. I need to apply it to all Rectangles inside Grid.

XAML:

<Grid Rectangle.MouseEnter="Grid_MouseEnter"><Rectangle Fill="Red"/></Grid>

C#:

        private void Grid_MouseEnter(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(sender.ToString()); // System.Windows.Controls.Grid
            MessageBox.Show(e.OriginalSource.ToString()); // System.Windows.Controls.Grid
        }

C# WPF) How to prevent controls not to be blurred in ViewBox when stretched?

$
0
0

I'm developing a WPF desktop application. In MainWindow, there're 100 controls entirely wrapped in ViewBox.

Usually, the Stretch setting of ViewBox is None and all the controls are seen clearly as deleloped.

However, I've coded that if my appliation runs under lower resolution(of computer monitor), the Stretch setting of ViewBox is changed to Uniform to be adjusted to lower resolution. And then all controls become blurred as the ViewBox stretches to be smaller.

I've made all the setting of controls in ViewBox as SnapsToDevicePixels=true and UseLayoutRounding=true. Doing these setting is positive or negative to this case?

Is there some solution for this case?

Or, if we divide Grids into many colums and rows to accomodate each controls, does this guarantee 100% all the controls are seen clearly on every different resolutions?

As always, Thank you so much !

Folder Browser Dialog

$
0
0

I need provide the user with the ability to select a folder, is there an alternate way other than referencing the Windows Forms version?


Performance issue for VirtualizingStackPanel in .NET 4.6.1

$
0
0

After upgrading to .NET 4.6.1, a datagrid using VirtualizingStackPanel started experiencing performance issues.

It seems the stack panel kept looping through all elements of the grid's data source in order to calculate row heights, even though the height of the row's grid is fixed.

It breaks our data virtualization, since all collection elements are accessed, and not only those that are visible at a given time.

Setting IsVirtualizingStackPanel_45Compatible to TRUE in the appSettings restores the performances as they were in 4.5.2, but we do not know what other consequences are.

There seems to be a bug in datagrid virtualization introduced in .NET 4.6.1



Add a button for each row in a listview

$
0
0

I have a listview populated with data from database and a iwould like to add a button in the last column for each row displayed in the listview here is my XAML : 

<ListView x:Name="listView" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="520" Margin="27,57,0,0" VerticalAlignment="Top" Width="1133"><ListView.View><GridView x:Name="gridView"><GridViewColumn><GridViewColumn.CellTemplate><DataTemplate><CheckBox Tag="{Binding fournisseur}" IsChecked="True"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding fournisseur}" Width="280"><GridViewColumn.Header><GridViewColumnHeader Tag="Fournisseur" Command="{Binding SortCommand}">Fournisseur</GridViewColumnHeader></GridViewColumn.Header></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding email}" Width="280"><GridViewColumn.Header><GridViewColumnHeader Tag="Email" Command="{Binding SortCommand}">Email</GridViewColumnHeader></GridViewColumn.Header></GridViewColumn><GridViewColumn Header ="Date" DisplayMemberBinding="{Binding date}" Width="150"/><GridViewColumn Header="Fichier CSV" DisplayMemberBinding="{Binding files}" Width="370"><GridViewColumn.CellTemplate><DataTemplate><Button x:Name="OpenFile" Tag="{Binding}" Content="Open File" CommandParameter="{Binding}" Click="OpenFile_OnClick"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn></GridView></ListView.View></ListView>

and here is my c# code where i fill my listview : 

TOPSAGEEntities db = new TOPSAGEEntities();
            var query = from fournisseur in db.F_COMPTET
                        join email in db.F_ECHEANCES on fournisseur.CT_Num equals email.CT_Num
                        where EntityFunctions.TruncateTime(email.cbModification) == EntityFunctions.TruncateTime(DatePicker.SelectedDate)
                        select new { fournisseur = (string)email.ECH_Intitule, email = (string)fournisseur.CT_EMail, date = (DateTime)email.cbModification};

            //List Data from Database into the ListView
            listView.DataContext = query.ToList().Distinct();
what's wrong with my code ?

Can I use open source WPF controls to develop my commercial Excel add-in software?

$
0
0


We have developed an Excel add-in platform which uses below packages:

- Main.Controls.Wpf.Notification.2.8.1.0
- GMap.NET.WindowsForms.1.7.1
- Extended.Wpf.Toolkit.2.5
- EPPlus.4.0.4

We have downloaded them from Codeplex and Syncfusion for free. Are we allowed to use this free packages in our software commercial version or we should purchase the licenses from somewhere? 

Any help would be really appreciated.

Thanks

TextBox Lost focus while user type

$
0
0

Hello Friends

I am working on one type of calculator project. In that I am using Mahapps Metro control. Its working fine but some time when user type on textbox or select on combobox  project lost  focus on particular control. I couldn't able to find the reason. I just want to know Why control loosing there focus ? How I can overcome this problem.  Why this problem occurring? etc.

I didnt implemented selection change event on that textbox, just simple text binding which holds string property, and for combox I ave bind collection property and selectedItem property, Combobox implements selection change event. 

My both controls (textbox and Combobox) loose there focus some time. 

 

Modify ResizeMode after Borderless Transparent Styleless window is Show()'n

$
0
0

I have a WPF window with these properties:

WindowStyle="None"

AllowsTransparency="True"

ResizeMode = "NoResize"

I want to be able to programmatically re-enable/disable the sizing grips which I could do with WinForms. But it seems I am unable to change them.  Whatever ResizeMode I set in XAML is permanent.

What do I need to do to get CanResizeWithGrip working after Show()?

Reset selection on grid of images

$
0
0

I have a datagrid that has one column which is an image.  There can be many rows.  When the image is clicked, a larger view of the that image displays.  The user can then close that larger view and return to the datagrid.  

This code to display the larger view is in the SelectionChanged event of the grid.  The user may decide to redisplay the larger view so the selected item on the grid must be reset so that this event can fire again.

This error displays if  the larger view is closed and the image is clicked on again.


I've tried the following to clear the selected item from the grid but all give me the above error:

    Private Sub btnCloseImage_Click(sender As Object, e As RoutedEventArgs) Handles btnCloseImage.Click

        grdCabinetImage.Visibility = Visibility.Hidden
        dgImages.SelectedItem = Nothing
        'dgImages.UnselectAllCells()
        'dgImages.SelectedCells.Clear()
        'dgImages.SelectedItems.Clear()
Thanks for any help or advice.



emcustom


How to handle Executed event of CommandBinding using MVVM rules?

$
0
0

I have a DataGrid and I want to turn off SelectAll() method on DataGrid
To be precise this button:

 enter image description here

Here is Executed event which will be handled in code behind:

<DataGridItemsSource="{Binding EmployeeDataTable}"Name="dataGrid"><DataGrid.CommandBindings><CommandBindingCommand="ApplicationCommands.SelectAll"Executed="SelectAll_Executed"></CommandBinding></DataGrid.CommandBindings></DataGrid>

code behind:

privatevoidSelectAll_Executed(object sender,ExecutedRoutedEventArgs e){//dataGrid.SelectAll();//I commented this line so user cannot select all rows //in a datagrid         }

The above code perfectly works and a user cannot select all rows in DataGrid and that is what I want. But I want to move handler of event(SelectAll_Executed) to viewModel.

What I've tried:

<DataGridItemsSource="{Binding EmployeeDataTable}"Name="dataGrid"><DataGrid.CommandBindings><CommandBindingCommand="ApplicationCommands.SelectAll"><i:Interaction.Triggers><i:EventTriggerEventName="Executed"><i:InvokeCommandActionCommand="{Binding Path=SomeCommand, Mode=OneWay}"/></i:EventTrigger></i:Interaction.Triggers></CommandBinding></DataGrid.CommandBindings></DataGrid>

But I've met such error:

The attached property "Triggers" can only be applied to types that are derived from "DependencyObject". DataGridAddedColumns

How to handle Executed event of CommandBinding using MVVM rules?

Treeview with "unlimited" sub-nodes

$
0
0

Hi.

the previous project i worked on and asked little about here went fine.

Now they want to be able to put  more or less "unlimited" sub-nodes in the treeview.

The source data would come in this format

Stockholm\Södertälje;101;Hovsjö;digital2;
Stockholm\Södertälje;102;Geneta;digital3;
Stockholm\Kungens Kurva;101;Lindvreten;digtal1;
Stockholm\Kungens Kurva;102;Lindvretsbacken;digtal4;

Where "Stockholm\Södertälje" is the root\subNode\Subnode format.
The Hovsjö, Geneta, Lindvreten, Lindvretsbacken is the items that will updates using the information in the OPC tag digital[1-4]

I have tried a few ways to add all the roots and sub-nodes in the right way, but i have yet to achieve the goal to produce several sub-sub-nodes

Do anyone have any tips how i could go about to add several subnodes into each others using the source data above?

Each node is a copy of this class

    public class Thing : INotifyPropertyChanged
    {
        private SolidColorBrush _statusBrush;
        public SolidColorBrush StatusBrush
        {
            get { return _statusBrush; }
            set { _statusBrush = value; NotifyPropertyChanged("StatusBrush"); }
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; NotifyPropertyChanged("Name"); }
        }

        private string _tag;
        public string Tag
        {
            get { return _tag; }
            set { _tag = value; NotifyPropertyChanged("Tag"); }
        }

        private string _status;
        public string Status
        {
            get { return _status; }
            set { _status = value; NotifyPropertyChanged("Status"); }
        }


        private string _parentnode;
        public string ParentNode
        {
            get { return _parentnode; }
            set { _parentnode = value; NotifyPropertyChanged("ParentNode"); }
        }

        public ObservableCollection<Thing> Children { get; set; }


        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }


Render an Office document in a WPF application

$
0
0

Dear all,

What is the proper way to render and office document like word, excel into a wpf application and be able to consult those document in a friendly way using touch.

Does the best way is to convert them into an XPS document and then render that document into a kind of wpf document control with page navigation ?

or is there an other solution ?

I guess we need to have office licence install to be able to do that no ?

thanks for advise

regards

TreeView bound to XmlDataProvider not updated when XmlNode modified

$
0
0

My application is basically a specialized XML editor. I display the XmlDocument in a TreeView declared as:

<TreeView Name="asifTreeView"
                ItemTemplateSelector="{StaticResource treeItemTemplateSelector}"
                SelectedItemChanged="asifTreeView_SelectedItemChanged"
                PreviewTextInput="asifTreeView_PreviewTextInput"
                ItemsSource="{Binding Mode=TwoWay, XPath=*}"
                Loaded="asifTreeView_Loaded"
                Margin="5"/>

The DataContext is an XmlDataProvider that is created by this code:

            Data = new XmlDataProvider();
            Data.XPath = "*";
            Data.DataChanged += Data_DataChanged;

For XmlElement nodes with a single XmlText node (which hold the data for my application), treeItemTemplateSelector returns this HierarchicalDataTemplate:

<HierarchicalDataTemplate x:Key="textNodeTemplate"><StackPanel Orientation="Horizontal"
              ToolTip="{Binding Converter={StaticResource xmlNodeToToolTipConverter}}"
              ContextMenu="{Binding Converter={StaticResource xmlNodeToContextMenuConverter}}"><TextBlock Text="{Binding Path=Name}"/><TextBox Text="{Binding Path=FirstChild.Data, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/></StackPanel></HierarchicalDataTemplate>

In my view model I track the changes to the content of the TextBox by handling the NodeChanged event:

                doc.NodeChanged += NodeChangedHandler;

 
private void NodeChangedHandler(Object src, XmlNodeChangedEventArgs args)
{
    UndoStack.Push(new EditorOperation(args));
}

Then I implement 'Undo' by doing:

        public void Perform_Undo()
        {
            if (UndoStack.Count > 0)
            {
                EditorOperation changeData = UndoStack.Pop();

                if (changeData.Action == XmlNodeChangedAction.Change)
                {
                    changeData.Node.Value = changeData.OldData;
                 }
            }
       }

I can see the XmlNodeChanged event fire and I record the change in my UndoStack. When the Perform_Undo() function is called I see the data in the XmlDocument change, but the TextBox in the TreeViewItem is not.

I had an earlier problem with data going the other way (changes made in the TextBox not being propogated to the XmlDocument) but that was fixed by adding UpdateSourceTrigger=PropertyChanged to the ItemTemplate in the HierarchicalDataTemplate.

Can anyone explain why the binding does not seem to be working in this case? How do I fix it?

Thanks,

Bill

NVDA Screen reader is not reading out WPF button press

$
0
0
In winforms when you press a button NVDA reads the action as "pressed" where as in WPF NVDA just reads the button name and does not read the pressed action

Apply button click function on a a single row records of a listview

$
0
0

i have a listview with buttons on each row i want to open csv files of the the name of the row concerned, i match the the name of the fournisseur with the name of the csv file if it's a match the button in the row of this fournisseur should open the file.

here is my code : 


 private void OpenFile_OnClick(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < listView.Items.Count; i++)
            {
                dynamic currentItemInLoop = listView.Items[i];
                String frs = (String)currentItemInLoop.fournisseur;
                DateTime myDate = (DateTime)currentItemInLoop.date;
                string myPath = @"C:\Users\DefaultAccount\Desktop\Projet Top Of Travel\FichiersCSV\";
                string fac = "Facture_";
                string filename = string.Format(frs);
                filename = Regex.Replace(filename + " " + myDate, @"[^0-9a-zA-Z]", " ");
                string finalPath = System.IO.Path.Combine(myPath, fac + filename + ".csv");
                string[] dirs = Directory.GetFiles(@"C:\Users\DefaultAccount\Desktop\Projet Top Of Travel\FichiersCSV\", "*.csv");
                if (finalPath.Contains(frs))
                {
                    Process.Start(finalPath);
                }
            }
        }
<GridViewColumn Header="Fichier CSV" Width="360"><GridViewColumn.CellTemplate><DataTemplate><Button x:Name="OpenFile" Content="Open File" Click="OpenFile_OnClick" Width="350"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn>

Drawing on Canvas vs Drawing using OnRender

$
0
0
I need to draw shapes using WPF. I have figured out two ways of doing this.  
Method 1

    protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            Rect rect = new Rect(new System.Windows.Point(50, 50), new System.Windows.Size(400, 100));
            drawingContext.DrawRectangle(System.Windows.Media.Brushes.Aqua, (System.Windows.Media.Pen) null, rect);
        }
      
Method2

        public void Draw()
        {
             DrawingVisual drawingVisual = new DrawingVisual();
             DrawingContext drawingContext = drawingVisual.RenderOpen();
             Rect rect = new Rect(new System.Windows.Point(50, 50), new System.Windows.Size(400, 100));
             drawingContext.DrawRectangle(System.Windows.Media.Brushes.Aqua, (System.Windows.Media.Pen) null, rect);
             drawingContext.Close();
             canvas.Children.Add(new VisualHost { Visual = drawingVisual });
        }
          public class VisualHost : UIElement
         {
             public Visual Visual { get; set; }
             protected override int VisualChildrenCount
             {get { return Visual != null ? 1 : 0; } }
             protected override Visual GetVisualChild(int index)
             {return Visual;}
         }


How are these different? Am able to draw and display using both methods.Since OnRender is an override provided, will it make more draws compared to my draw function? When should I use one over the another? Please guide. TIA
Viewing all 18858 articles
Browse latest View live


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