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

Two WPF windows have KeyboardFocus and both are activated

$
0
0

I have two WPF windows, one is none topmost and another is topmost. Following is the code for none topmost window. For topmost window, simply set the Topmost to true in .xaml file.

<Window x:Class="WpfApplication7.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" Topmost="False"
        xmlns:local="clr-namespace:WpfApplication7"><Grid><TextBlock x:Name="target" HorizontalAlignment="Center" VerticalAlignment="Center" Height="40" Width="400"/></Grid></Window>

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        this.IsKeyboardFocusedChanged += MainWindow_IsKeyboardFocusedChanged;
    }

    void MainWindow_IsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        if (this.IsKeyboardFocused)
        {
            target.Text = "Keyboard Focused and IsActive is " + this.IsActive.ToString();
        }
        else
        {
            target.Text = "Lose keyboard focus and IsActive is " + this.IsActive.ToString();
        }
    }
}

My question is why both of them can have Keyboard Focus and are activated after following operation:

1. Click on topmost window;

2. Press the Windows logo key;

3. Click the icon of none topmost window in task bar;

Then you will find that both two windows show "Keyboard Focused and IsActive is True".


Problem to run .exe file

$
0
0
Hi,
I can build the WPF project on the server and can also run the generated .exe file on the machine. But if I copy the relevant .exe to another Win 8.1 or Win 10 machine, I then cannot run it. why?

Many Thanks & Best Regards, Hua Min

How to achieve a 'wrapping' DataGrid effect?

$
0
0

I have information that is best displayed in a tabular format or rows and columns. However, the data itself has a fair number of rows but only a few columns. Due to constraints in the layout the result is a cluster of columns on the left with a great deal of unused screen space on the right. The perfect solution would be for the data to wrap in much the same fashion as one would achieve using a ListBox that displays rows of multiple columned data using a WrapPanel as the means by which the rows of data object would be presented. While the data presented in the fashion that was desired the loss of the column header row was objected to by the people that will be using the program.

Maybe a visual of what the View looks like when using a DataGrid will better illustrate the problem and make it clearer what I'd like to accomplish.

My first attempt at this was to use a ListBox and insert the WrapPanel in it. I was able to get the columns I wanted but could not figure out how to detect when the wrap panel wrapped a new column and so could not figure out how to insert a new row header. Any ideas?


Richard Lewis Haggard

XpsDocumentWriter.Write() : Bad quality when FixedPage's contents is VisualBrush.

$
0
0

Hi, all.

Please execuse my poor english! :)

I have a strange problem with XpsDocumentWriter.

I wrote sample program to test Xps printing as below:

        private void CreateXps()
        {
            FixedDocument fd = new FixedDocument();
            FixedPage fp = new FixedPage();
            PageContent pc = new PageContent();
            pc.Child = fp;
            fd.Pages.Add(pc);


            Canvas canvas = new Canvas();
            {
                canvas.Width = 500;
                canvas.Height = 500;

                TextBox tbx = new TextBox();
                tbx.Width = 200;
                tbx.Height = 25;
                tbx.Text = "hi, there";
                Canvas.SetTop(tbx, 10);
                Canvas.SetLeft(tbx, 10);
                canvas.Children.Add(tbx);
                canvas.Measure(new Size(500, 500));
            }


            VisualBrush vb = new VisualBrush(canvas);
            vb.TileMode = TileMode.None;
            vb.Stretch = Stretch.None;
            vb.Viewport = new Rect(0, 0, 1, 1);
            vb.Viewbox = new Rect(0, 0, 1, 1);
            vb.AlignmentX = AlignmentX.Left;
            vb.AlignmentY = AlignmentY.Top;

            Rectangle rect = new Rectangle();
            rect.Fill = vb;
            rect.Width = canvas.Width;
            rect.Height = canvas.Height;

            fp.Children.Add(rect);
            fp.Measure(new Size(canvas.Width, canvas.Height));
            fp.Arrange(new Rect(new Point(), new Size(canvas.Width, canvas.Height)));


            //
            // (1) FixedDocument will be displayed fine in DocumentViewer
            //
            Window window = new Window();
            DocumentViewer dv = new DocumentViewer();
            dv.Document = fd;
            window.Content = dv;
            window.Show();

            //
            // (2) But its image is blurred when serialized to xps file bia XpsDocumentWriter...
            //
            using (XpsDocument xpsDocument = new XpsDocument(@"C:\temp\myfile.xps", FileAccess.Write, CompressionOption.NotCompressed))
            {
                XpsDocumentWriter w = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
                w.Write(fd);
                xpsDocument.Close();
            }
        }

Problem:

As the comment says, FixedDocument displayed in DocumentViewer is pretty good quality.

But its quality become bad when FixedDocument is serialized to XPS file with XpsDocumentWriter.

I'd like to create Xps file as fine as an image displayed in DocumentViewer.

Any suggestions?



[WPF][ShowDialog] Error when execute 2nd Window in 2nd screen by ShowDialog

$
0
0

Hi to all,

I have an Xaml app 

It supposed to Execute ONLY in Second screen

The first window call the 2nd by this code:

Hide();
PickingWindow _PickingWindow = new PickingWindow();
_PickingWindow.ShowDialog();
Show();

Just when the debug goews to ShowDialog, error message appears with message "ShowDialog can be called only in hidden windows"

in order the window to execute in the second screen I have:

private void WorkInScreen(int Screen) { System.Drawing.Rectangle workingArea = System.Windows.Forms.Screen.AllScreens[Screen].WorkingArea; this.Left = workingArea.Left + 10; this.Top = workingArea.Top; this.Width = workingArea.Width; this.Height = workingArea.Height; this.Show(); }

private void Window_Loaded(object sender, RoutedEventArgs e)
{
 WindowState = WindowState.Maximized;
}


What am I missing?

Thanks in advance



WPF - Using behaviors for instantiating view model and services

$
0
0

I am trying to find the best practice for creating view models and services (service just talks to the server and return data back to view model). I have seen 2 different approaches.

  1. Using view model locator
  2. Using behaviors (I am not sure if this is good approach)

For the second approach, you define a behavior on UserControl and on attach event you create an instance of view model and an instance of service and put them all together.

protected override void OnAttached()
    {
        var service = Activator.CreateInstance(ServiceType)
        var viewModel = Activator.CreateInstance(ModelType);
        base.AssociatedObject.DataContext = viewModel;
        base.OnAttached();
    }

and in your usercontrol xaml

<i:Interaction.Behaviors><be:ViewModelBehaviorViewModelType="{x:Type vm:ViewModel1}"ServiceType="{x:Type serv:Service1}"/></i:Interaction.Behaviors>

Is this a good use of behaviors, or I should just use viewmodel locator pattern.

DataGrid ComboBox Binding to Model

$
0
0
I'm trying to bind my DataGridComboBoxColumn to a contract model that I have defined like this; 

    public class ContractPresetsModel
    {
        public int ContractID { get; set; }
        public string ContractText { get; set; }
        public string ContractReference { get; set; }
    }

I have tried binding using SelectedValuePath, DisplayMemberPath and ItemsSource however every time the ComboBox is A) only displaying when the user clicks on a cell and B) is completely empty.

This is how I am attempting to bind the ComboBox now;

<DataGridComboBoxColumn  Header="Contract Reference" Width="*" SelectedValueBinding="{Binding ContractReference}"/>
How should I bind the ComboBox differently?

Open new Window from WebBrowser

$
0
0

Hello 

I display ASP Page in WebBrowser WPF application (MainWindow).

This page contain a button.

On button click, i would like to open another Window (Window1)

Please, how can i do that?

Thanks


User edit resource file

$
0
0
Hi, we have a software write in c# WPF. This software is translated in 6 languages with resources files.
It's possible give the possibility at users to write resoure files for other languages? 

Thanks in advice

cant get style for validation error in wpf

$
0
0

Person.Cs

private string _Pwd;
        public string Pasword
        {
            get
            {
                return _Pwd;
            }
            set
            {
                if (_Pwd != value)
                {
                    _Pwd = value;
                    OnPropertyChanged("Pasword");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public string Error
        {
            get { throw new NotImplementedException(); }
        }

 public string this[string columnName]
        {
            get
            {
                string result = "";
                if (!string.IsNullOrEmpty(Pasword) && Pasword.Length < 6)
                {
                    result="Enter maximium 6 digit character";
                }
                return result;   
            }
        }

PasswordBoxAssistant.cs      //this class for dependency property of Passwordbox

{

//////...//////////

}

xaml:

<Window x:Class="ITA.AdminMaster"
        xmlns:local="clr-namespace:ITA"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="AdminMaster" Height="567" Width="917">
    <Window.Resources>
        <local:Person x:Key="person"/>
        <local:PasswordBoxAssistant x:Key="PBA"/>
        <Style TargetType="{x:Type Label}">
            <Setter Property="Margin" Value="5,0,5,0"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
        </Style>
       
        <Style x:Key="PassVallidationTemplate" TargetType="{x:Type PasswordBox}">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Margin" Value="0,2,40,2" />
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel LastChildFill="true">
                            <Border Background="OrangeRed" DockPanel.Dock="right" Margin="5,0,0,0"
                                Width="20" Height="20" CornerRadius="5"
                                ToolTip="{Binding ElementName=customAdorner,
                                          Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
                                <TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center"
                                   FontWeight="Bold" Foreground="white" />
                            </Border>
                            <AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center">
                                <Border BorderBrush="red" BorderThickness="1" />
                            </AdornedElementPlaceholder>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
</Window.Resources>

<PasswordBox x:Name="Pwd" HorizontalAlignment="Left" Validation.Error="Validation_Error" Style="{StaticResource PassVallidationTemplate}"
                            local:PasswordBoxAssistant.BindPassword="True" local:PasswordBoxAssistant.BoundPassword="{Binding Path=Pasword,UpdateSourceTrigger=LostFocus,ValidatesOnExceptions=True,NotifyOnValidationError=True}"
                             VerticalAlignment="Top" Grid.Column="3" Grid.Row="3" Width="133" Height="21" Margin="0" Grid.RowSpan="2"  />    // here i cant get style of validation error for max length

</Window>

cs

private int _errors = 0;
        private Person p = new Person();
   
        public AdminMaster()
        {
            InitializeComponent();
            grid_AdminData.DataContext = p;
        }

private void Validation_Error(object sender, ValidationErrorEventArgs e)
        {
            if (e.Action == ValidationErrorEventAction.Added)
                _errors++;
            else
                _errors--;
        }

Combobox with close button in the dropdown

$
0
0

Hi,

I want to make a ComboBox whose design as follows:


If I click the Toggle button, a popup should appear right below the comboBox, and the popup should some data along with close button (to close that current popup).

I can achieve most of things by using the control template, and the ItemTemplatePanel to UniformGrid to achieve as shown in the image.

But I am facing problems for giving the close button in the popup of the popup.

How to give close button over there in popup?


I have tried to add a button in the controltemplate of the combobox inside the popup as shown below:-

<Popup
                            Name="Popup" Placement="Bottom"
                            IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True"
                            Focusable="False" PopupAnimation="Slide"><Grid Name="DropDown" SnapsToDevicePixels="True"
                              MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}"><ScrollViewer Grid.Row="1" Margin="4,6,4,6" SnapsToDevicePixels="True"><Grid><Grid.RowDefinitions><RowDefinition Height="0.2*"/><RowDefinition Height="0.8*"/></Grid.RowDefinitions><Grid Grid.Row="0" Width="30" Height="30" Background="Brown"><Button Content="X" Width="30" Height="30" Background="Brown"/></Grid><StackPanel IsItemsHost="True" Grid.Row="1" Height="300"
                                                        KeyboardNavigation.DirectionalNavigation="Contained" /></Grid></ScrollViewer></Grid></Popup>

But when I try to show the items in the combobox, like

<Combobox><ComboboxItem>1</ComboboxItem><ComboboxItem>2</ComboboxItem><ComboboxItem>3</ComboboxItem></Combobox>


the button is not visible in the dropdown.

I also thought to add the multiple datatemplates using CompositeCollection but uniform grid will take the control of where the data should be displayed. 
So I am unable to use that option also.

I can mock up this one, by a seperate user control which consists of textbox and a button and a itemscontrol with the itemtemplate. 

But I want to achieve this, by Combobox.

May I kindly know, how to achieve this ?

Thanks in advance.


NANDAKUMAR.T

WPF UserControl Issue - IsArrangeValid = False

$
0
0

Hi

I work for a company developing Point of Sale applications.  We have a control which lists the bill details (quanity / description / price etc).  This was initially data-bound but I'm re-writing this as code because the performance improvement is significant (3-4 times faster).

The Sales Screen includes my control in the WPF as

                <my:WPFRegWindow x:Name="RegWindow" Height="240" Width="240" ></my:WPFRegWindow>

It's actual height and width is set at run-time from DB configration when the screen refreshes.

Because POS layouts can change (product buttons added or removed etc.) the till can get a message to redraw.

The problem I'm getting is really weird.  If I have 140 lines or less in a order OR the sales screen is active when the refresh happens (through a Dispatcher) then everything refreshes correctly.  But, if the sales screen isn't active and I have 141 lines or more in the order, the refresh fails and RegWindow.IsArrangedValid = False.  Also, the control is 'disabled' - kinda like it IsEnabled was false.  I can't move the scroll bar etc.

A condensed version of the WPF is

<UserControl x:Class="WPFRegWindow"
             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"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
        <ScrollViewer x:Name="Scroller"
                   Width="{Binding Path=Width, ElementName=me}"
                   Height="{Binding Path=Height, ElementName=me}"
                      VerticalScrollBarVisibility="Visible"
                      Background="White"
                                  HorizontalScrollBarVisibility="Disabled"
                                  >
            <StackPanel
                            IsHitTestVisible="True"
                            Focusable="False">
                <ListBox x:Name="ItemList"  
                                     VirtualizingStackPanel.IsVirtualizing="True"
                                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                     VerticalAlignment="Stretch"
                                     HorizontalAlignment="Stretch"
                                     IsSynchronizedWithCurrentItem="False"
                                     IsEnabled="True"
                                     IsHitTestVisible="True"                        
                                     BorderBrush="Transparent"
                                     SelectionMode="Multiple"
                                     Focusable="True" >
                </ListBox>

            </StackPanel>
        </ScrollViewer>
</UserControl>

And the code to populate is

    Public Class RegWindowItemStackPanel
        Inherits StackPanel
        Public TIRow As dsTransactionData.tblTransactionItemsRow
    End Class

    Public Sub ShowTransactionTest(Transaction As clsTransaction)
        ItemList.Items.Clear()

        If Transaction IsNot Nothing Then
            ItemList.Items.Clear()

            For Each TIRow In Transaction.TransactionDS.tblTransactionItems
                Dim regWindowItem As New RegWindowItemStackPanel With {.TIRow = TIRow}

                Dim dock = New System.Windows.Controls.DockPanel With {
                    .Height = Double.NaN,
                    .Width = Me.ItemList.ActualWidth,
                    .LastChildFill = True
                }

                Dim itemTextBlock = New System.Windows.Controls.TextBlock With {
                    .Height = Double.NaN,
                    .Padding = New System.Windows.Thickness(0, 0, 2, 0),
                    .Text = TIRow.ItemText
                }

                dock.Children.Add(itemTextBlock)

                regWindowItem.Children.Add(dock)

                ItemList.Items.Add(regWindowItem)
            Next
        End If
    End Sub

I use a dock panel as the real code has multiple items in the row (a grid is too restrictive for widths).

WPF is still a little voodoo to me so I'm probably doing something - or many things :) - badly, but I just can't get why there is such a definite cut-off point between working and not.

Any guidelines would be very much appreciated for my sanity.

Cheers

Mike


wpf c# Save code needed

$
0
0

this is the save file code which is really a saveas code

Is there a save code available

 private void cmdSave_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.Filter = "XAML Files (*.xaml)|*.xaml|RichText Files (*.rtf)|*.rtf|All Files (*.*)|*.*";

            if (saveFile.ShowDialog() == true)
            {
                // Create a TextRange around the entire document.
                TextRange documentTextRange = new TextRange(
                    richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd);

                // If this file exists, it's overwritten.
                using (FileStream fs = File.Create(saveFile.FileName))
                {
                    if (System.IO.Path.GetExtension(saveFile.FileName).ToLower() == ".rtf")
                    {
                        documentTextRange.Save(fs, DataFormats.Rtf);
                    }
                    else
                    {
                        documentTextRange.Save(fs, DataFormats.Xaml);
                    }
                    this.Title = "Hyfler Writer: " + saveFile.FileName;
                }
            }
        }


How to sort columns of ListView bound to ADO.NET Table: Problems referencing static C# properties inside XAML

$
0
0

My WPF MSMQ/WCF client is working nicely except that I cannot dynamically sort the columns in the ListView. The list view is bound to an ADO.NET DataSet/DataTable.

After some boogle searching I found some nice sample code at 

http://www.thomaslevesque.com/2009/08/04/wpf-automatically-sort-a-gridview-continued/

  and the code even works! Hurray! It sorts the columns with a nice little triangle glyph in the ListView header to indicate ascending or descending sort order. However, I want to use this code in my WPF application. So I use Visual Studio to add a reference to C:\Users\siegfried\Documents\Examples\WPF\AutoSortGridView\bin\Debug\AutoSortGridView.exe

Then to test it I add this code to my C#:

var x = new Wpf.Util.GridViewSort();

This compiles. When I single step thru with the debugger I see all the properties and it looks good to me. So it looks to me like I have correctly created a reference to the sample code.

However, when I edit the XAML for my application, I add the following in the window declaration:

xmlns:util="clr-namespace:Wpf.Util"

Wpf.Util is the C# namespace the author of the sorting demo used.

This does not cause a problem. Then I add ' util:GridViewSort.PropertyName="complete"' to the following line of XAML:

<GridViewColumn Header="Complete" DisplayMemberBinding="{Binding Path=complete}" Width="200px"  util:GridViewSort.PropertyName="complete" />

I get this syntax error:

Error 1 The property 'GridViewSort.PropertyName' does not exist in XML namespace 'clr-namespace:Wpf.Util'. Line 25 Position 117. C:\Users\siegfried\Documents\Examples\WCF\C#\CodeProject\MSMQ Service With No Security\MSMQNoSecurityClient\MSMQNoSecurityClient\MainWindow.xaml 25 117 MSMQNoSecurityClient

Why am I getting this syntax error? This is the same code in the sample I downloaded and it works in the sample!

How do I fix this syntax error? The original author of the sample code was binding to an array of C# Person objects. I am binding to an ADO.NET Data Table. Is that causing the problem? If so, how do I bind to Table or DataSet so I can use the sample code I found.

Both projects are being compiled with VS 2013/.NET Framework 4.5/Windows 8.1 Pro.

Thank you,

Siegfried


siegfried heintze

WPF TreeView children nodes disappear after selection

$
0
0
I created a simple treeview control with a few children nodes using the below code - in a new wpf project. I selected one of the child nodes (after expanding the parent) and then collapse the parent. After that the expand collapse of the parent essentially stops working and I can no longer see the children.
Steps to duplicate the issue:
1. Create a new wpf project
2. Insert the code below in the Grid element
<TreeView Height="153" HorizontalAlignment="Left" Margin="3,6,0,0" Name="treeView1" VerticalAlignment="Top" Width="495" >
            <TreeViewItem Header="All Tests" >
                <TextBlock Name="Test" Text="Test" />
                <TextBlock Name="Test2" Text="Test2" />
                <TextBlock Name="Test3" Text="Test3" />
            </TreeViewItem>
        </TreeView>
3. Run the project
4. Expand "All Tests" by clicking on the +
5. Click on one of the children
6. Collapse "All Tests" by clicking on the +
7. Try expanding and collapsing "All Tests" by clicking on the +/-

What should I create instead of Bootstrapper? Prism 6.1.0

$
0
0

I've tried to update my application from Prism v4.0 to Prism v6.1.0 and run package manager: PM> Install-Package Prism.Core

and PM has installed such packages:

  • Microsoft.Practices.Prism.Composition.dll
  • Microsoft.Practices.Prism.Interactivity.dll
  • Microsoft.Practices.Prism.Mvvm.dll
  • Microsoft.Practices.Prism.Mvvm.Desktop.dll
  • Microsoft.Practices.Prism.PubSubEvents.dll
  • Microsoft.Practices.Prism.SharedInterfaces.dll
  • Microsoft.Practices.ServiceLocation.dll

The next step I've tried to create bootstrapper:

public class Bootstrapper : UnityBootstrapper
{
    protected override DependencyObject CreateShell()
    {
        return Container.Resolve<Shell>();
    }
    protected override void InitializeShell()
    {
        base.InitializeShell();
        App.Current.MainWindow = (Window)Shell;
        App.Current.MainWindow.Show();
    }
    protected override void ConfigureContainer()
    {
        base.ConfigureContainer();
        Container.RegisterType<IShellViewModel, ShellViewModel>();
    }
    protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
    {
        RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
        mappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>());
        return mappings;
    }
    protected override IModuleCatalog CreateModuleCatalog()
    {
        ModuleCatalog catalog = new ModuleCatalog();
        catalog.AddModule(typeof(ModuleBModule));
        return catalog;
    }
}

and I've tried to resolve the UnityBootstrapper. However, there is no such a class at Prism 6.1.0. So I've tried to install by Nuget:

Prism.UnityExtesions

However NuGet says: This package is no longer supported. Please use the new Prism.Unity package. So to my mind come the question: How to create bootstrapper at Prism 6.1.0?


How do I add a row to a datagrid with a button click event?

$
0
0

I am new to WPF XAML, which I write in VB.NET and have a datagrid which is populated using a stored procedure. How do I add a row to my datagrid in a button click event? The datagrid and the button are in separate row definitions.

Thanks.

Chris


Blur Behind option for WPF Controls within the application

$
0
0

Hi,

I am trying to create a UI in WPF 4.6 similar to the one shown here
http://i1-news.softpedia-static.com/images/news2/Windows-10-Looks-Stunning-in-New-Design-Concept-468398-5.jpg


I was able to add the blur behind option to the Window based on the excellent tip from the blog article by Rafael RiveraAdding the "Aero Glass" blur to your Windows 10 apps.

 
However, I have another question related to this. This solution applies the blur effect to the entire window. How can I modify your solution so that a child control within the window has the same blur effect over the window content. For e.g. a blurred and translucent title bar at the top of a Listbox which shows the topmost content below as blurred when the user scrolls the listbox contents. 
 
Also, can I extend this solution to make the context menus also translucent.

As per the blog article, the SetWindowCompositionAttribute is not properly documented. Could you please provide some links or info on how to use the powerful DWM to obtain such effects within the application?


Thanks

ListView Item Highlight Shape

$
0
0

Hi,

I am trying to create a horizontal listview with circular icons.

While I can change the color of the selection highlight, I have no idea how to change the square/rectangle highlight.

Since this is a rather generic question, I have no idea whether my code is important but in case it is needed - 

<UserControl
    x:Class="MyProject.Pages.CustomControls.ActionBarControl.FActionBar"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="MyProject.Pages.CustomControls.ActionBarControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ActionBarButton="MyProject.Pages.CustomControls.ActionBarControl.ActionBarButtons"
    mc:Ignorable="d" Loaded="UserControl_Loaded"
    d:DesignWidth="400"
    d:DesignHeight="70"><UserControl.Resources><Style x:Key="FActionBarListViewStyle" TargetType="ListViewItem"><Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/><Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/><Setter Property="Background" Value="Transparent"/><Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}"/><Setter Property="TabNavigation" Value="Local"/><Setter Property="IsHoldingEnabled" Value="True"/><Setter Property="Padding" Value="0"/><Setter Property="HorizontalContentAlignment" Value="Center"/><Setter Property="VerticalContentAlignment" Value="Center"/><Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/><Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="ListViewItem"><ListViewItemPresenter CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                                               ContentMargin="{TemplateBinding Padding}"
                                               CheckMode="Inline"
                                               ContentTransitions="{TemplateBinding ContentTransitions}"
                                               CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                                               DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
                                               DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
                                               DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
                                               DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
                                               FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
                                               FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
                                               HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                               PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
                                               PressedBackground="WhiteSmoke"
                                               PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
                                               PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
                                               ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
                                               SelectedPressedBackground="WhiteSmoke"
                                               SelectionCheckMarkVisualEnabled="True"
                                               SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
                                               SelectedPointerOverBackground="White"
                                               SelectedBackground="White"
                                               VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/></ControlTemplate></Setter.Value></Setter></Style></UserControl.Resources><Border CornerRadius="10" BorderBrush="{StaticResource ActionButtonBorderColor}" BorderThickness="3"  Background="{StaticResource ControlsBackground}"><Grid><Grid.RowDefinitions><RowDefinition Height="7*"></RowDefinition></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition/></Grid.ColumnDefinitions><ListView x:Name="listView_Buttons" Grid.Row="0"
                      ItemsSource="{Binding ListButtons}"
                      SelectedItem="{Binding SelectedItem,Mode=TwoWay}"
                      Background="Transparent"
                      ScrollViewer.VerticalScrollBarVisibility="Disabled"
                      ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                      ScrollViewer.HorizontalScrollMode="Enabled"
                      ScrollViewer.VerticalScrollMode="Disabled"
                      ItemContainerStyle="{StaticResource FActionBarListViewStyle}"><ListView.ItemTemplate><DataTemplate><ActionBarButton:ActionBarButton HorizontalAlignment="Center" VerticalAlignment="Center"></ActionBarButton:ActionBarButton></DataTemplate></ListView.ItemTemplate><ListView.ItemsPanel><ItemsPanelTemplate><VirtualizingStackPanel Background="Transparent" Orientation="Horizontal" HorizontalAlignment="Stretch" Height="60"><VirtualizingStackPanel.ChildrenTransitions><TransitionCollection><EntranceThemeTransition FromVerticalOffset="400" /><RepositionThemeTransition/></TransitionCollection></VirtualizingStackPanel.ChildrenTransitions></VirtualizingStackPanel></ItemsPanelTemplate></ListView.ItemsPanel></ListView></Grid></Border></UserControl>
Note: The ActionBarButton is just another UserControl that contains the Round Icon Image.

Edit: I just realized that I have posted this question in the WPF section. This is actually a Windows 10 Application (UWP?) project so if possible, please help me move the question to the relevant section.

Thanks in advance for any help.

How to refresh ListView or Datagrid when Database changes?

$
0
0

I'm experimenting with ListViews and Datagrids whose itemssource is pointing to an ADO.NET datatable.

I'm using VS 2013 on Windows 8.1.

While I'm using MS Access presently, I could be using MS SQL Server later.

When my database changes

(1) How do I detect the change? For MS SQL Server, I suppose I could define a trigger (but what would the trigger do?). For MS Access, I could use the Directory/File watch feature (System.IO.FileSystemWatcher). Is there some feature built into WPF that would detect the change for me? How is this usually done? I suppose I could create a background thread that re-runs the query once every 30 seconds.

(2) After I detect the change, perhaps by polling with a background thread, how do I trigger a refresh for the datagrid or listview? Would I have to use Dispatch.Invoke? If so, to do what?

Thanks

Siegfried


siegfried heintze

Viewing all 18858 articles
Browse latest View live


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