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

WPF Richtextbox undo and Redo Operation with syntax hightlight

$
0
0

I am using RichTextBox in one of my WPF Application, users types Text\script in this rich text box, based on the tokens entered by user i apply color, font property to the entered text in the code behind(Syntax highlighting).

I need to perform Undo\Redo Operations, but what i found is the default undo operation works well if i am not changing the color\font properties, but if i change them in my code , it doesn't work.

Is there any issues with Richtextbox ?


Changing brightness of window (Form)

$
0
0

Hi,
   I have a WPF application that have multiple forms/user controls. I would like reduce brightness of active form if form is ideal (No movement on the form) for 90 seconds and become dark gradually as time increases. I am using themes in the application and currently is it set to blue. Also I would like to add this functionality all forms being displayed.
  What is the best way to achieve this? I am using VB.Net , VS2013.

Thank you

Guy

ContextMenu on DataGrid side issue

$
0
0

Hi,

I have a very simple ContextMenu on a DataGrid and when I right click, the Context Menu appears on the LEFT rather than on the RIGHT.  Why is that ? Is it the default ? What to do to have the Context Menu appears on the right of the mouse ?

.NET 4.5
Visual Studio 2013 Community

issue fixed in WindowsFormsIntegration.dll

$
0
0

Hi,

There's an issue in WindowsFormsIntegration.dll, in class ApplicationInterop, which did not check for the menu state in the right time. The problem exists in version4.0.30319.1, and is fixed in version4.0.30319.17929. How can I know which .Net framework version the fix can be found in? I know it is not in the original .Net 4.5 version, but I need to know which version it is in, and is it available for .Net 4.0 as well.

Yoel

WPF by C-Pad programming

$
0
0

C-Pad is what i intrepret as cmd and notepad programming.I have done VB.Net and C# with C-Pad successfully--given any complicated programme.Even with 250 textboxes,12 butons etc etc.

 I am trying the same with wpf.I am not geting a grip of it.Can any expert suggest a simple programme where in a simple wpf programme--say messagebox with "Hello,world" is achieved.I shall follow it up from there.I am getting difficulty in calling the compiler and also how to compile the xaml file with vb file.Thanks in advance.

   I am not a professional programmer.I am aged 68 and is interested in prgrammming as a hobby.

Thanks in advance.

Venkatraman

On selecting an item in combobox, UI goes behind the main application but combobox are still functional.

$
0
0

On some machines, we are facing an issue, where sometimes if we select an item in combobox, the main UI goes into background.

Suppose a User control has 2 combobox. Selecting an item in first shifts the UI into the background and when user clicks on the area, where second combobox was, before UI went into background, the dropdown list appears but still the User control remains in background.

This User control has been launched in a non-modal way( so that main app Excel 2010 can be accessed) and topmost property has been set to true, the owner of this UI has been set to excel using windowinterophelper so that it doesn't float on other application.

All our machines have Win 7, 64 bit.

This issue occurs sporadically but when it happens, it occurs on all UIs, for all combobox. Only way to use the application in this situation, is to restart the application. Any ideas or workarounds to avoid this behavior?

WPF DataGrid Slow Loading during render

$
0
0

I have a WPF DataGrid with almost 8000 Rows. It's taking approx. 25 seconds to load. Any clues how do I improve its performance?

This Grid has 3 static ButtonType Columns and other columns are dynamic. I fetch data inside a list and assign it to the ItemsSource property of the DataGrid on CodeBehind.

Here is the XAML code:

<UserControl x:Class="TransportApp.Views.CommonScreen.SideBar.DetailsGrid"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300"><Grid Margin="5,0,0,0" VirtualizingStackPanel.IsVirtualizing="True"><Grid.RowDefinitions><RowDefinition Height="60"/><RowDefinition Height="1*"/><RowDefinition Height="5" /></Grid.RowDefinitions><Grid Grid.Row="0"  HorizontalAlignment="Left"><Grid.ColumnDefinitions><ColumnDefinition Width="1*"/><ColumnDefinition Width="120"/><ColumnDefinition Width="30"/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="30"/><RowDefinition Height="30"/></Grid.RowDefinitions><Label Name="DisplayHeader" Grid.Row="0" Content="Information" VerticalAlignment="Center" FontSize="20" /><DatePicker Name="dtGridFilterDate" Grid.Column="1" Grid.Row="0" Margin="4" SelectedDate="{x:Static sys:DateTime.Now}"/><mui:ModernButton Name="Cmd_Refresh" Grid.Column="2" Grid.Row="0" ToolTip="Click to Refresh View" IconData="{StaticResource RefreshIconData}" EllipseStrokeThickness="2" EllipseDiameter="26" IconHeight="15" IconWidth="15" Click="Cmd_Refresh_Click"/><DockPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1"><Label FontWeight="Bold" DockPanel.Dock="Left" Name="lblFilter" Content="Filter" VerticalAlignment="Center"/><TextBox DockPanel.Dock="Right" Margin="4" HorizontalAlignment="Stretch" Grid.Column="1" VerticalContentAlignment="Center" Name="filterBox1"/></DockPanel><mui:ModernButton Name="cmdSearch" Grid.Column="2" Grid.Row="1" ToolTip="Click to Search" IconData="{StaticResource SearchData}" EllipseStrokeThickness="2" EllipseDiameter="26" IconHeight="11" IconWidth="11" Click="cmdSearch_Click"/></Grid><DataGrid Name="DG_Details" Grid.Row="1"
                      AutoGenerateColumns="True" IsReadOnly="True"
                      CanUserAddRows="False" CanUserDeleteRows="False"
                      SelectionMode="Single" EnableRowVirtualization="True"
                      VirtualizingStackPanel.IsVirtualizing="True"
                      AutoGeneratingColumn="DG_Details_AutoGeneratingColumn"
                      HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled"><DataGrid.Columns><DataGridTemplateColumn x:Name="dgEditColumn"><DataGridTemplateColumn.CellTemplate><DataTemplate><mui:ModernButton Name="Cmd_Edit" Click="Cmd_Edit_Click" ToolTip="Edit" IconData="{StaticResource EditIconData}" EllipseStrokeThickness="2" EllipseDiameter="20" IconHeight="10" IconWidth="10"/></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridTemplateColumn x:Name="dgDeleteColumn"><DataGridTemplateColumn.CellTemplate><DataTemplate><mui:ModernButton Name="Cmd_Delete" Click="Cmd_Delete_Click" ToolTip="Delete" IconData="{StaticResource DeleteIconData}" EllipseStrokeThickness="2" EllipseDiameter="20" IconHeight="10" IconWidth="10"/></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridTemplateColumn x:Name="dgPrintColumn" Visibility="Hidden"><DataGridTemplateColumn.CellTemplate><DataTemplate><mui:ModernButton Name="Cmd_Print" Click="Cmd_Print_Click" ToolTip="Re-Print document" IconData="{StaticResource PrintIconData}" EllipseStrokeThickness="2" EllipseDiameter="20" IconHeight="10" IconWidth="10"/></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid></Grid></UserControl>

A thing to note here is, DataGrid's performance is great after loading. No lag at all. I am using a Core i5 machine with 4 GB RAM and 512 MB graphics card.

Please let me know if any optimizations can be done in this code.


NB


Change the image in combobox for selected items ?

$
0
0

 Hello ,

  I have combobox in which i am displaying image and textblock. What i want to do is that change the image when user select particular item.

<ComboBox x:Name="CmbSelect" Foreground="#666" BorderBrush="#C5C5C5" SelectedIndex="0" SelectionChanged="CmbSelect_SelectionChanged" MaxWidth="245"><ComboBox.ItemTemplate><DataTemplate><StackPanel Orientation="Horizontal"><Image Width="16" Height="16"><Image.Style><Style TargetType="Image"><Style.Triggers><DataTrigger Binding="{Binding Type}" Value="2"><Setter Property="Source" Value="selfblk.png"></Setter></DataTrigger><DataTrigger Binding="{Binding Type}" Value="1"><Setter Property="Source" Value="calblk.png"></Setter></DataTrigger></Style.Triggers></Style></Image.Style></Image><TextBlock Text="{Binding Name}" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}},
                                      Path=ActualWidth}"></TextBlock></StackPanel></DataTemplate></ComboBox.ItemTemplate></ComboBox>

I am using two image, which image will be shown on the particular item that is depend on the type. Now i want that when user select any item then image for that item will be changed ( a new image, shape is same but just show that it is selected).

How do i can change image when user select item ..?


Is it possible to read .xaml file content to string?

$
0
0

Is it possible to read xaml file (that is in the project) as string with, for example, relative uri?

/ProjectName;component/Themes/Default/Core.xaml

XamlWriter is not suitable because of some attributes are discarded after it was loaded. 

The final purpose is to create an extandable application (with System.AddIn) which looks like a single unit (with a single style). Every AddIn can open a window.

The idea was to set addin's theme by sending them all host application's dictionaries. Are there other ways to do it?

Thanks in advance

How can user control inherit a user control?

$
0
0

I have a user control "Cell" with different methods.

I need 2 other user controls to Inherit from "Cell".

I was told to change "Cell" to a class without a xaml, I did it, and to ensure that the subclass inherits from the base class both in the cs code-behind file and in the first tag of the xaml.

how do I do it?

and, how do I know that now the user controls will have the same base class?

Howto set transparent the background of the items in a treeview?

$
0
0

I have a treeview and I set the background of the items with a multivalue converter, so I would like to set transparent the default selection color to show the color that I set in the multivalueconverter.

I am trying this:

<Treeview Name="mytreeView"><TreeView.Resources><HierarchicalDataTemplate DataType="{x:Type ViewModels:MynodeViewModel}" ItemsSource="{Binding Path=Childrens}"><StackPanel Orientation="Horizontal"></TextBlock><TextBlock Text="{Binding Path=Node.Property1}" /><TextBlock Text=" ("/><TextBlock Text="{Binding Path=Node.Property2}"/><TextBlock Text=")"/></StackPanel></HierarchicalDataTemplate><SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /><SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" /><SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" /><SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Black" /></TreeView.Resources><TreeView.ItemContainerStyle><Style TargetType="{x:Type TreeViewItem}"><Setter Property="Behaviors:TreeViewItemBehavior.IsBroughtIntoViewWhenSelected" Value="True" /><Setter Property="IsExpanded" Value="{Binding IsExpanded, NotifyOnSourceUpdated=True}" /><Setter Property="IsSelected" Value="{Binding IsSelected, NotifyOnSourceUpdated=True}" /><Setter Property="FontWeight" Value="Normal"/><Setter Property="Background"><Setter.Value><MultiBinding Converter="{StaticResource myMultiValueConverter}"><MultiBinding.Bindings><Binding /><Binding ElementName="ucPrincipal" Path="DataContext.MyProperty1"/><Binding ElementName="ucPrincipal" Path="DataContext.MyProperty2"/></MultiBinding.Bindings></MultiBinding></Setter.Value></Setter><Style.Triggers><Trigger Property="IsSelected" Value="True"><Setter Property="FontWeight" Value="Bold" /></Trigger></Style.Triggers><Style.Resources><SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/><SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/><SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent"/><SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Black"/><SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/></Style.Resources></Style></TreeView.ItemContainerStyle></Treeview>

How it is shown, I have tried to set transparent "HighlightBrushKey" and "InactiveSelectionHighlightBrushKey", in the resources of the tree view and in the resources of the ItemContainerStyle, but the result is the same, when I select an item, the color that I set in my multivalue converter is hidden by the default color of the selected item.

How can I set transparent the color of the selected item to show the color of my multivalue converter?

Thank so much.

textBox1.Handle in WPF

$
0
0

I'm transleting code from windows form (C#) to WPF

In the c# code   I have "textBox1.Handle" but the WPF says: 

'System.Windows.Controls.TextBox' does not contain a definition for 'Handle' and no extension method 'Handle' accepting a first argument of type 'System.Windows.Controls.TextBox' could be found (are you missing a using directive or an assembly reference?)

How do i  write it correctly in WPF?

How can user control inherit a user control - continue ?

$
0
0

Thanks for your answer written very clearly.

But it's still not working

i have an Error:

Inconsistent accessibility: base class 'UserControls.Cell' is less accessible than class 'UserControls.HintCell'

what should i do?

textBox1.Handle in WPF

$
0
0

where should i put the code:

IntPtr handle =newSystem.Windows.Interop.WindowInteropHelper(this).Handle;

and:

when i try to paste it in the constructor it tells me:

The best overloaded method match for 'System.Windows.Interop.WindowInteropHelper.WindowInteropHelper(System.Windows.Window)' has some invalid arguments

maybe i need to write it differently or add something?

How can user control inherit a user control - continue 2?

$
0
0

in the xaml, i wrote like u said:

<local:Cell x:Class="UserControls.SimpleCell"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:UserControls"

but it doesn't show the designer now, it says that there is an error, and it underlines (in blue) the bold code,

what should i do?


textBox1.Handle in WPF - 2

metadata

$
0
0

suddently, i got an error:

Metadata file 'Z:\WPF\Kakuro WPF\UserControls\bin\Debug\UserControls.exe' could not be foundKakuro

what should i do?

If statements mixed with switch

$
0
0
This is probably fairly simple and I'm just overlooking it, but how do I make something so that every time i click the mouse a variable goes up 1 value. This variable is used for reference in a case structure. So say the variable is at 2 and the mouse gets clicked its now at 3 and the code reads whatever is in case 3.

How to load embedded picture into image control from code

$
0
0

I would like to load a picture I embedded into my project, into an image control, using C# code.

  1. I added the file "Password_Icon.jpg" to my project, via the Project | Add Existing Item command in Visual Studio.
  2. I set the Build Action property of the picture file to "Embedded Resource."
  3. Next, I added the following code to my app.
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            Stream myStream = myAssembly.GetManifestResourceStream("DC_Password_Saver.Password_Icon.jpg");
            System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage();

            image.StreamSource = myStream;
            MyImageControl_image.Source = image;
        }

Note: DC_Password_Saver, is the Namespace for the main window for my app. This is why it precedes the name of my app, in the 4th line of the code.

The code above executes, but nothing happen. Can someone suggest a solution to my problem? Thanks in advance for your help.

Image properties

$
0
0
private void MyCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
            Point mousePosition = e.GetPosition(MyCanvas);
            Image img = new Image();
            img.Source = new BitmapImage(new Uri("2box.png", UriKind.Relative));
            img.Height = 42;
            img.Width = 44;
            MyCanvas.Children.Add(img);
            Canvas.SetTop(img, mousePosition.Y-22);
            Canvas.SetLeft(img, mousePosition.X-21);
}

Is there a way to use this and give the image properties such as being able to be moved and removed?

Viewing all 18858 articles
Browse latest View live


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