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

Performance issue with the Blur effects.

$
0
0

Hello. I have many(dozens) of elements with blur effects. The problem is it's working slow.

Then I tried such settings:

<BlurEffect x:Key="Effect"
                KernelType="Box"
                RenderingBias="Performance"
                Radius="1.5"/>

It became better but still not good enough. What can you advice to solve this issue? I can try to write custom blur effect but it would be the last resort.


Grid cellleave event is not firing sometimes

$
0
0
Hi i am new to WPF ..i need to do some validations on grid ..so i Wrote cell leave event in grid .but the problem is ..if i edit the cell in grid and immediatly i clicked on other control like button which is not in grid then that button click event is firing.. please help me..

Header template is setted but the header is null

$
0
0
I set a header template using dynamic XAML:
DataGridTemplateColumn tc = new DataGridTemplateColumn();publicstaticstring GetHeaderDataTemplate(string bindingPath)
{return@"<DataTemplatexmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" ><TextBlock Text=""{Binding Path="+ bindingPath + @"}""TextWrapping=""Wrap""Foreground=""#FF1EA800""FontWeight=""Bold"" /></DataTemplate>";
}

tc.HeaderTemplate = (DataTemplate)XamlReader.Parse(GetHeaderDataTemplate(someText));



But there is nothing in the place of datagrid column header. It is just an empty place. So I tried to get access to the header and got null reference exception.
How to set a header data template in the right way?





Detecting Sleep State on Tablet PC

$
0
0

When WPF application runs on windows 10 tablet pc, do we have any option to detect its shift to sleep state? PowerModeChanged event can be handled on desktop pc if it goes to sleep, but that cannot be handled on tablet.

As some service stop during sleep, I need to detect the state.

Thanks in advance.

Binding path to get bookmarks in tree view form.

$
0
0

I am working in WPF for converting bookmarks into xml doc and then binding the xml into tree view to display the bookmarks into tree view.

My code is:

<Window.Resources>

            <HierarchicalDataTemplate x:Key="NodeTemplate"

           ItemsSource="{Binding XPath=./*}">

           <TextBlock x:Name="nodetext"/>

           <HierarchicalDataTemplate.Triggers>

               <DataTrigger Binding="{Binding Path=NodeType}" Value="Element">

     <Setter TargetName="nodetext" Property="Text" Value="{Binding XPath = Title}" />

                   </DataTrigger>

           </HierarchicalDataTemplate.Triggers>

       </HierarchicalDataTemplate>

    </Window.Resources>

      <Grid>

       <Grid.RowDefinitions>

           <RowDefinition />

           <RowDefinition Height="Auto" />

       </Grid.RowDefinitions>

      <TreeView Name="trvItems" Grid.Row="0"

           ItemsSource="{Binding}" ItemTemplate="{StaticResource NodeTemplate}">


Using this:

<SetterTargetName="nodetext"Property="Text"Value="{BindingXPath= Title}" />

I am getting simple text in display but not in tree view, need to display in tree view format.

CS code:

 public MainWindow()
        {
            InitializeComponent();
        }
        private void btnAFM_Click(object sender, RoutedEventArgs e)
        {
           string filename = System.AppDomain.CurrentDomain.BaseDirectory;
            filename = @"D:\xyz.pdf";
            string outputbookmark = @"D:\abc.xml";
            var Sbytes = File.ReadAllBytes(filename);
            PdfReader pdfReader = new PdfReader(Sbytes);
            IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pdfReader);
            using (StreamWriter Sw = new StreamWriter(outputbookmark))
            {
            SimpleBookmark.ExportToXML(bookmarks, Sw, "ISO8859-1", true);
            }
            XmlDocument doc = new XmlDocument();
            doc.Load(outputbookmark);
            XmlDataProvider provider = new XmlDataProvider();
            provider.Document = doc;
            provider.XPath = "./*";
            var bookmark = XmlParser<Bookmark>.Deserialize(outputbookmark);
             trvItems.DataContext = provider;
         }
    }

enabling different buttons based on text in textBox in WPF

$
0
0
Hi. I am facing a problem. I have a textbox and multiple buttons. when i type text into textbox, then depending on the text in the text box, the appropriate button gets enabled. However if I read data from a .txt file into text Box, then the buttons dont get enabled. Can someone tell me the problem..

Error to write ArcSegment to an XPS document in fr-FR culture

$
0
0

Hi,

I meet one strange problem in writing a visual including ArcSegment control.

Here is the xaml code:

        <Canvas x:Name="canvas" Margin="20" Width="300" Height="300">
            <Path Stroke="Red" StrokeThickness="3" Fill="Yellow">
                <Path.Data>
                    <PathGeometry>
                        <PathFigure StartPoint="113 113" IsClosed="True">
                            <LineSegment Point="113 0" IsStroked="True" />
                            <ArcSegment x:Name="arc" Size="113 113" IsLargeArc="True" SweepDirection="Clockwise" RotationAngle="340.5"
                                        Point="75.18 6.51"/>
                            <LineSegment Point="113 113" />
                        </PathFigure>
                    </PathGeometry>
                </Path.Data>
            </Path>
            <Path Stroke="Red" StrokeThickness="3" Fill="Red">
                <Path.Data>
                    <PathGeometry>
                        <PathFigure StartPoint="113 113" IsClosed="True">
                            <LineSegment Point="113 0" />
                            <ArcSegment x:Name="arc2" Size="113 113" IsLargeArc="False" SweepDirection="Counterclockwise" RotationAngle="19.5"
                                        Point="75.18 6.51"/>
                            <LineSegment Point="113 113"/>
                        </PathFigure>
                    </PathGeometry>
                </Path.Data>
            </Path>
        </Canvas>

and here the code to write this canvas to an xps document:

            //var cultureInfo = CultureInfo.GetCultureInfo("en-US");
            var cultureInfo = CultureInfo.GetCultureInfo("fr-FR");
            Thread.CurrentThread.CurrentCulture = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;

            string strXpsFile = $"C:\\temp\\{Guid.NewGuid().ToString()}.xps";

            var document = new XpsDocument(strXpsFile, FileAccess.ReadWrite);
            var xpsdw = XpsDocument.CreateXpsDocumentWriter(document);
            var vToXpsD = xpsdw.CreateVisualsCollator();
            vToXpsD.Write(canvas);
            vToXpsD.EndBatchWrite();
            document.Close();

I get a broken xps document.

If I change the culture to en-US, or the InvariantCulture. or make the RotationAngle to an integer instead of a decimal value, I can get the correct xps document. Seems related to the decimal separator.

Do you have any idea about this?


Path Not Showing Correctly

$
0
0

Hi,

I am having some issues with getting my vector icons into my WPF application.

Whenever I paste my path data in to draw my image I place the path data inside a grid which is inside a button and the content isn't displayed correctly.

Here is what it looks like.

Am I going wrong somewhere?

Also is there a way to group the two path data together so it makes it easier to move the graphic around?

Thanks!



How to set an word in center position of Richtextbox using WPF?

$
0
0

Hi,

I want to set word by word navigation i n richtextbox. I already done.But In that navigation,each word highlight in the left corner and the hide.But i want to highlight a word in center position of the richtextbox. So my query is,

1.How to get that top center position of the WPF Richtextbox and how to set words in that position?
2.How to set that current caret position into center top of the Richtextbox?

3.Any predefined API is there for setting a caret position in top center of the richtextbox? 

Regards

Sanju

Applying a default style to a control without including resource dictionary in the xaml.

$
0
0
Hello. Let's say I have a style and I need to apply it to all controls of a particular type inside application. I want that happen even for controls that created in code as well. But since they are created in code I can't include that style in xaml. Actually I'm creating them in winforms app. How can it be achieved?

wpf datagrid and combobox

$
0
0

      this code only shows the text when you click the dropdown and select(it is correct)
the drop down does not show text from a separate table

any help would be appreciated, maybe a project I can download.

thanks, tom

       

<DataGridTemplateColumnx:Name="AC_Limit_FrequencyColumn"Header="Frequency"Width="SizeToHeader">

<DataGridTemplateColumn.CellTemplate>

<DataTemplate>

<ComboBoxSelectedItem="{BindingFrequency Required}"TextElement.Foreground="ForestGreen">

<ComboBoxItemContent="{BindingAC Limit Frequency}"TextElement.Foreground="Red"/>

</ComboBox>

</DataTemplate>

</DataGridTemplateColumn.CellTemplate>

</DataGridTemplateColumn>


Tom

How do I dynamically add buttons to grid?

$
0
0

Hello,

I'm struggling getting started on this one so I hope someone can point me in the right direction.

I need a window that allows users to enter a number and from that number I generate that number of buttons in a grid. These buttons require a tag and a right click context menu.

<Button x:Name="button" Content="" Margin="6,15,1,1" Click="Button_Click" Grid.Row="1" Style="{StaticResource MyButton}" Tag="button" Grid.Column="1"><Button.ContextMenu><ContextMenu><MenuItem Header="{x:Static p:Resources.Add}" Click="RightClickButton_Click" Tag="button" /><MenuItem Header="{x:Static p:Resources.Delete}" Click="RightClickReset_Click" Tag="button" /></ContextMenu></Button.ContextMenu></Button>

I use the tag to read and write values to user settings. button(x)label, button(x)file.

I have looked at dynamically creating a grid but I cannot seem to create new colums/rows based upon an int as they seem to need a hard coded name rather than a dynamic one.

Hopefully someone can point me in the right direction.

Sorry for what is potentially a very simple solution.

How I can add treeview item into tree view item with more then one level with DataTemplate and Item Source in WPF

$
0
0

How I can add treeview item into tree view item with more then one level with DataTemplate and Item Source in WPF?

I have tree view in that I have multilevel treeview items each item of tree have child into item and child item also have item then if I want to fill this details with item source, How I can manage to do it without use of hierarchicaldatatemplate

Multiple GroupBox Controls Dynamically

$
0
0

How to add GroupBox with inside controls  into grid When each Checkbox clicks Dynamically in WPF.

When CheckBox1 Click in ListBox1  into grid it will adding another ListBox2 with checkbox values into same grid.it is working fine.

But When i check another checkbox2 click in ListBox1 it will adding checkbox value into same listbox2 .

Error:  In this I want to add Another listbox or groupbox list for check box2 click below listbox2 into same grid . Dynamically 


 

Can any one explain Visual Studio UndoRedoManager stucture?

$
0
0
I was asked to created UndoRedo manager for Single Page WPF Application. So i have created a UndoRedoManager class which has Undo and Redo Stack (which is a stack of class which have old and new values and other operation). Now, if i want to convert the code to support Multipage application, what structure i should follow.

For example, i'm creating an application with many views like visual studio in MVVM pattern.

So to support undoredo, i have to store the model in which the edit action has been happened. If i did like that, will it create memory leak(cause i'm holding the model instance)?

Can any one guide me or explain the visual studio UndoRedoManager stucture?

Selected valued not work with combo box in wpf mvvm

$
0
0

We want to show sleeted value in the combo box. We are coding as follows.

1-I have created property for showing the value

private string _severityValue = "Select...";
        public string SeverityValue
        {
            get { return _severityValue; }
            set
            {
                SetProperty(ref this._severityValue, value);
                RaisePropertyChanged("SeverityValue");
            }
        }


And xaml design is as follows

<ComboBox Grid.Row="5" Grid.Column="0" Name="SeverityComboBox"  Width="150" Height="30" StaysOpenOnEdit="True" IsSynchronizedWithCurrentItem="True"
                                     SelectedValue="{Binding RepairRecommendationsModel.SeverityValue, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Top"
                                       IsEditable="False" IsTextSearchCaseSensitive="False"  Margin="5,0,0,0" MaxHeight="30" MinHeight="30"><ComboBoxItem Content="Select..."/><ComboBoxItem Content="Unit Down" /><ComboBoxItem Content="Possible Failure" /><ComboBoxItem Content="Preventative Maintenance" /></ComboBox>

When we run the application then it's not showing selected value. We are unable to determine the issue.

Please help to find out solution. thanks


Multiple progressbar control used in lisview WPF

$
0
0

Hi to all,

I want to use multiple progressbar controll used in listview . how its possible.

When my data is uploaded than progresbar status is done show.

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.

.net chm help.showHelp opens blank Glossary

$
0
0

Hi. I have a problem with displaying .chm help from wpf application.

After calling 

Help.ShowHelp(null, filePath);

Help is displayed but Glossary Tab is blank.

If I open .chm file using 

Process.Start(filePath);

Glossary displayes correctly.

Can you please advice?

Whats the best way to refresh a listbox and label with WPF?

$
0
0

listBox.Refresh() works great in WinForms. But there is no equivalent in WPF. I'm looking for a way to accomplish this, I have come across several ways of doing this. All of which are confusing to me as a beginning programmer. There is...

Asych/Await

Backgroundworker

OberservableCollections with INotifyProperty Changed

etc...

It seems crazy to me that a single line of code has to be replaced with quite a few more to accomplish the goal with what is a newer technology. Don't get me wrong, WPF looks great and I really want to start using it as a replacement for WinForms. Below is a simplified version of what I'm looking to do. Can anyone tell me which direction to go please?

My XAML:

<Window x:Class="ListBoxUpdate.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ListBoxUpdate"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525"><Grid><StackPanel><ListBox x:Name="listBox" HorizontalAlignment="Left" Height="187" VerticalAlignment="Top" Width="260"/><Label x:Name="label" Content="Label" HorizontalAlignment="Left" VerticalAlignment="Top"/><Button x:Name="button" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="button_Click"/></StackPanel></Grid></Window>

My C#

using System;
using System.IO;
using System.Windows;

namespace ListBoxUpdate
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            string[] filesFound = Directory.GetFiles(@"c:\Test\", "*.txt", SearchOption.AllDirectories);

            foreach (String file in filesFound)
            {
                listBox.Items.Add(file);
                label.Content = file;
            }

            label.Content = "Done";
        }
    }
}

Thanks.

understanding a piece of code where datatype has +

$
0
0

Hi,

I have following piece of code.

<UserControl.Resources>
        <DataTemplate DataType="{x:Type BaseControls:MainMenuViewModel+MenuItem}">
            <Grid x:Name="OuterGrid" Height="20">
                <!-- some xaml -->
            </Grid>
        </DataTemplate>
       <!-- some xaml -->
</UserControl>

I do not understand this line of code.

 <DataTemplate DataType="{x:Type BaseControls:MainMenuViewModel+MenuItem}">

Can someone please explain me what is happening with + here "MainMenuViewModel+MenuItem"

Thanks.

Viewing all 18858 articles
Browse latest View live


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