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

want message loop in worker thread

$
0
0

I want a message loop in a worker thread to accomodate some 3rd-party software. The software raises events and, when run in the UI thread, blocks the UI for longer than it should.

Something like

Application app = new Application();

app.Run(new MyHiddenWindow(... args ...);

won't work. The msdn docs say 1 instance of the Application class per AppDomain. So I think I need another AppDomain in the process. Together with communication between the 2 AppDomains. Am I missing something simpler?


Bill Swartz


WPF MVVM pattern to CSV file

$
0
0

Hi All,

I am new to MVVM pattern and WPF also. If i have designed to generate 100 queries to display in the Grid and it needs to be converted as CSV format. Is this possible to do it ?


SaranRam

How to know the current Cell grid position

$
0
0

Dear all,

I need to build a game board which will be design by a graphical background as follow :

On top of the graphic board I will draw a grid in order to represent each cells.

In order to offer a rich interaction with the grid, I need to know when a user place the mouse over the whole grid, if the mouse coordinate is within white color cell, I will make the border of the cell wider.

What is the properway to identify the coordinate of each grid square in the screen in order to know if mouse pointer is inside a particular cell ?

Thnaks for help
regards

serge


Your knowledge is enhanced by that of others.

Restrict characters in decimal field in WPF (MVVM)

$
0
0

Hi,

My application is WPF with MVVM.

I have a decima field which is binded to a text box. I want to restrict the characters to that textbox. How can i achieve this?

public Nullable<Decimal> Weight
        {
            get { return _item.Weight; }
            set
            {
                if (value.HasValue)
                {
                    _item.Weight = value.Value;
                    _isDirty = true;
                    OnPropertyChanged(PropertyNames.Item_Weight);
                }
            }
        }

Here _item is an entity.

If the value is any character then default value is 0.

If i input the value some characters then it is not debugging at all...

Thanks, Sai

System.OutOfMemoryException: Insufficient memory to continue the execution of the program

$
0
0

Hi everyone,

I'm getting System.OutOfMemoryException when my WPF application runs for long time (~4-5 days). Application is written using .NET 4.0 and running on Windows7 embedded 64 bit. But application itself is complied in 32 bit. System has 4GB RAM. 

It freezes my whole system. I'm not able to access anything on the system... No mouse movement etc.

Any help would be highly appreciated! Thanks in advance!

Regards,

Stack Trace:

System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
 at System.Windows.Media.Composition.DUCE.Channel.CreateOrAddRefOnChannel(Object instance, ResourceHandle& handle, ResourceType resourceType)
 at System.Windows.Media.Composition.DUCE.MultiChannelResource.CreateOrAddRefOnChannel(Object instance, Channel channel, ResourceType type)
 at System.Windows.Media.GlyphRun.System.Windows.Media.Composition.DUCE.IResource.AddRefOnChannel(Channel channel)
 at System.Windows.Media.RenderData.System.Windows.Media.Composition.DUCE.IResource.AddRefOnChannel(Channel channel)
 at System.Windows.UIElement.RenderContent(RenderContext ctx, Boolean isOnChannel)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
 at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
 at System.Windows.Media.Visual.Render(RenderContext ctx, UInt32 childIndex)
 at System.Windows.Media.CompositionTarget.Compile(Channel channel)
 at System.Windows.Media.CompositionTarget.System.Windows.Media.ICompositionTarget.Render(Boolean inResize, Channel channel)
 at System.Windows.Media.MediaContext.Render(ICompositionTarget resizedCompositionTarget)
 at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
 at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
 at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

Change button styles depending on object property

$
0
0

Hello everyone,

I'm trying to modify in xaml the style of a button inside a listboxitem, when a property (the IsAlive property) of the bound object is true or false. This object contains three properties: Name, CmdAction and IsAlive.

Here it is the DataTemplate to apply to each listboxitem:

<DataTemplate x:Key="ListBoxItemTemplate"><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="50*"/><ColumnDefinition Width="50*"/></Grid.ColumnDefinitions><TextBlock Grid.Column="0" Text="{Binding Path=Name}"/><Button Style="{DynamicResource ???}" Command="{Binding Path=CmdAction}" /></Grid></DataTemplate>

The two styles of the buttons are:

<Style TargetType="{x:Type Button}" x:Key="MyButtonStyleON"><Style.Resources><SolidColorBrush x:Key="NormalBackgroundBrush" Color="LightGreen" /><SolidColorBrush x:Key="NormalBorderBrush" Color="LightGray" /><SolidColorBrush x:Key="NormalForegroundBrush" Color="White" /><SolidColorBrush x:Key="HoverBackgroundBrush" Color="Green" /><SolidColorBrush x:Key="HoverBorderBrush" Color="Black" /><SolidColorBrush x:Key="HoverForegroundBrush" Color="White" /><SolidColorBrush x:Key="PressedBackgroundBrush" Color="DarkGreen" /><SolidColorBrush x:Key="PressedBorderBrush" Color="Black" /><SolidColorBrush x:Key="PressedForegroundBrush" Color="Black" /></Style.Resources><Setter Property="Cursor" Value="Hand" /><Setter Property="Focusable" Value="False" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><Grid Background="Transparent"><Ellipse x:Name="BackgroundEllipse" StrokeThickness="2" Stroke="{StaticResource NormalBorderBrush}" Fill="{StaticResource NormalBackgroundBrush}"/><Path x:Name="ButtonPath" Margin="10" Stroke="{StaticResource NormalForegroundBrush}" StrokeThickness="2" StrokeStartLineCap="Square" StrokeEndLineCap="Square" Stretch="Uniform" VerticalAlignment="Center" HorizontalAlignment="Center"><Path.Data><PathGeometry><PathGeometry.Figures><PathFigure StartPoint="2,4"><LineSegment Point="4,8"/></PathFigure><PathFigure StartPoint="4,8"><LineSegment Point="8,0"/></PathFigure></PathGeometry.Figures></PathGeometry></Path.Data></Path></Grid><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="BackgroundEllipse" Property="Fill" Value="{StaticResource HoverBackgroundBrush}"/><Setter TargetName="BackgroundEllipse" Property="Stroke" Value="{StaticResource HoverBorderBrush}" /><Setter TargetName="ButtonPath" Property="Stroke" Value="{StaticResource HoverForegroundBrush}"/></Trigger><Trigger Property="IsEnabled" Value="false"><Setter Property="Visibility" Value="Collapsed"/></Trigger><Trigger Property="IsPressed" Value="true"><Setter TargetName="BackgroundEllipse" Property="Fill" Value="{StaticResource PressedBackgroundBrush}" /><Setter TargetName="BackgroundEllipse" Property="Stroke" Value="{StaticResource PressedBorderBrush}" /><Setter TargetName="ButtonPath" Property="Stroke" Value="{StaticResource PressedForegroundBrush}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>

<Style TargetType="{x:Type Button}" x:Key="MyButtonStyleOFF">
        <Style.Resources>
            <SolidColorBrush x:Key="NormalBackgroundBrush" Color="LightCoral" />
            <SolidColorBrush x:Key="NormalBorderBrush" Color="LightGray" />
            <SolidColorBrush x:Key="NormalForegroundBrush" Color="White" />

            <SolidColorBrush x:Key="HoverBackgroundBrush" Color="Red" />
            <SolidColorBrush x:Key="HoverBorderBrush" Color="Black" />
            <SolidColorBrush x:Key="HoverForegroundBrush" Color="White" />

            <SolidColorBrush x:Key="PressedBackgroundBrush" Color="DarkRed" />
            <SolidColorBrush x:Key="PressedBorderBrush" Color="Black" />
            <SolidColorBrush x:Key="PressedForegroundBrush" Color="Black" />
        </Style.Resources>
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid Background="Transparent">
                        <Ellipse x:Name="BackgroundEllipse" StrokeThickness="2" Stroke="{StaticResource NormalBorderBrush}" Fill="{StaticResource NormalBackgroundBrush}"/>
                        <Path x:Name="ButtonPath" Margin="10" Stroke="{StaticResource NormalForegroundBrush}"
                              StrokeThickness="2" StrokeStartLineCap="Square"
                              StrokeEndLineCap="Square" Stretch="Uniform"
                              VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Path.Data>
                                <PathGeometry>
                                    <PathGeometry.Figures>
                                        <PathFigure StartPoint="0,0">
                                            <LineSegment Point="8,8"/>
                                        </PathFigure>
                                        <PathFigure StartPoint="0,8">
                                            <LineSegment Point="8,0"/>
                                        </PathFigure>
                                    </PathGeometry.Figures>
                                </PathGeometry>
                            </Path.Data>
                        </Path>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="BackgroundEllipse" Property="Fill" Value="{StaticResource HoverBackgroundBrush}"/>
                            <Setter TargetName="BackgroundEllipse" Property="Stroke" Value="{StaticResource HoverBorderBrush}" />
                            <Setter TargetName="ButtonPath" Property="Stroke" Value="{StaticResource HoverForegroundBrush}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter TargetName="BackgroundEllipse" Property="Fill" Value="{StaticResource PressedBackgroundBrush}" />
                            <Setter TargetName="BackgroundEllipse" Property="Stroke" Value="{StaticResource PressedBorderBrush}" />
                            <Setter TargetName="ButtonPath" Property="Stroke" Value="{StaticResource PressedForegroundBrush}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



I would like to apply the MyButtonStyleON when the property IsAlive is true, and the MyButtonStyleOFF when the property IsAlive is false.

Can anyone help me please?

Thanks in advance,

FZ

WPF cant pause a MediaElement

$
0
0

Hey,

I placed a media element on a grid, added 2 buttons to browse for file and one button to play the file.

while playing the video im loading works well, the pause does not work.

Functions:

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Media Files (*.wmv)|*.wmv";
            ofd.ShowDialog();
            mediaElement1.Source = new Uri(ofd.FileName, UriKind.Absolute); 

        }

        private void pausebutton_Click(object sender, RoutedEventArgs e)
        {
            mediaElement1.Pause();
        }

XAML:

    <Grid>
        <MediaElement Height="120" HorizontalAlignment="Left" Margin="128,52,0,0" Name="mediaElement1" VerticalAlignment="Top" Width="160" UnloadedBehavior="Manual" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="144,254,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Button Content="Pause" Height="23" HorizontalAlignment="Left" Margin="250,254,0,0" Name="pausebutton" VerticalAlignment="Top" Width="75" Click="pausebutton_Click" />
    </Grid>

Can anyone have a look ? thanks

How to execute the batch file on the server side from client after uploading it : C#

$
0
0
I transfer (upload) the batch file to the server using FTP in C# (FtpWebRequest). Batch files have some commands. My requirement is to transfer the batch file to the server (which I am able to do) and execute that batch file.
 
How do I execute the commands in the batch file on the server from my client? Can I use Process.Start() approach or rsh?? Which is better way of doing it and a link to the example would be appreciated.
 
Thanks,
Nayan

Set ItemTemplateSelector via XAML Inheritance

$
0
0

I have 3 classes (ExpanderItem), (ExpanderControl), (TestControl).

--ExpanderItem

<UserControl>

-- namespace decl and other initialization code

<ItemsControl x:Name="ContentPanel" ItemTemplateSelector="{StaticResource DynamicSetFromParentControl}"><ItemsControl.ItemsPanel><ItemsPanelTemplate><VirtualizingStackPanel VerticalAlignment="Top" Orientation="Vertical"/></ItemsPanelTemplate></ItemsControl.ItemsPanel></ItemsControl>

</UserControl>

-- ExpanderControl contains a stackpanel of ExpanderItems

-- TestControl will contain an ExpanderControl and set the ItemsSource. This is where I will have my ItemTemplateSelector I'd like to pass/set for the ExpanderItems of my ExpanderControl.

I'd really like to be able to create the ItemTemplateSelector in the resources of my TestControl window and be able to someone enforce this template on the "ContentPanel" of the ExpanderItems through inheritance.

Can anyone please give me some advice on the proper way to handle such a situation.

Thank you!

Saving a document in shared folder

$
0
0

Hi I am under a task (in my wpf project) to save a document in shared folder,so any user of that system can view that document .

I want to know how i can get the shared folder path i.e(c:\users\public\documents) in windows 7 as well as in xp or in vista Os to save that document,

Pls provide me a solution regarding this

Thanks in Advance


Efforts may fail but don't fail to take effort -------------- sidd

How to bind a BitmapImage to Image control in xaml with "Binding"

$
0
0

Hello!

I am having some trouble with an image, and I hope somebody can help me, because I think I might be missing a very simple thing, it can't be sooo dificult!

I am developing a WPF application, that has to show an image, so I used a Image control. That image comes from a WCF service, that returns it like a byte[], then I convert it to a BitmapImage.

The first thing I tried was to put a button, and on the click event called the WCF service, convert the image and set it as Source of the Image control, and everything worked fine:

<Window x:Class="ImageTester.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="333.3" Width="356.631"><Grid><Button Height="23" Margin="19.278,21.42,0,0" Name="button1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="74.51" Click="button1_Click">Button</Button><Image Margin="19.278,78.54,0,0" Name="image1" Stretch="Fill" HorizontalAlignment="Left" Width="40" Height="40" VerticalAlignment="Top" /></Grid></Window>


private void button1_Click(object sender, RoutedEventArgs e)
{
            //get the image from the WCF service
            byte[] imgb = service_client.getImage();
            //Convert it to BitmapImage
            BitmapImage image = new BitmapImage();
            image.BeginInit();
            image.StreamSource = new MemoryStream(imgb);
            image.EndInit();
            //Set the image as Source of the control
            image1.Source = image;
}

So when I run the application and click the button the image is shown. The problem is that I don't want to do it from code-behind,  I need to do it in xaml through the Binding property of the Image control. I have been searching and found this solution:

<Window x:Class="ImageTester.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="333.3" Width="356.631"><Grid><Button Height="23" Margin="19.278,21.42,0,0" Name="button1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="74.51" Click="button1_Click">Button</Button><Image Margin="19.278,78.54,0,0" Name="image1" Stretch="Fill" HorizontalAlignment="Left" Width="40" Height="40" VerticalAlignment="Top" /><Image Width="90" Name="image2" Source="{Binding Path=ImageSource}" Margin="122.315,100.15,0,0" HorizontalAlignment="Left" Height="90" VerticalAlignment="Top" /><Button Height="23" HorizontalAlignment="Right" Margin="0,33.33,58.883,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click_1">Button</Button></Grid></Window>

I added a sencon image, "image2" and in the Source property y wrote "Binding Path=ImageSource". In the code-behind I added the object "IMageSource", so the get method returns the BitmapImage:

public partial class Window1 : Window
{
        public Window1()
        {
            InitializeComponent();
        }
        //......
        public object ImageSource
        {
            get
            {
                //Get the image from the WCF service
                byte[] ib = service_client.getImage();
                //Convert it to BitmapImage
                BitmapImage image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = new MemoryStream(ib);
                image.EndInit();
                //Return the image
                return image;
            }
        }
}

It all seems to be right, but it doesn't work, when I run the app and the page is loaded nothing happens, there is no image.

I don't know if I have to add something on the xam, like setting the ImageSource as a resource or something like that, because I usually do this kind of things from code behind, not from the xaml.

Hope somebody can help me, I will be grateful. Thanks!


Trigger Opacity of an ItemControls Datatemplate

$
0
0

Dear all,

I have an ItemsControl whihc has its ItemSource bind to amy ViewModel
The datatemplate used for that ItemsControl is define as follow :

<DataTemplate x:Key="ScoresTemplate"><Grid ><Grid.RowDefinitions><RowDefinition Height="40" /><RowDefinition Height="30"/></Grid.RowDefinitions><TextBlock x:Name="_player1" Padding="15" Grid.Row="0" Text="{Binding Name,UpdateSourceTrigger=PropertyChanged}" FontSize="15" FontFamily="Showcard Gothic" Foreground="#FFEBF409"/><TextBlock x:Name="_player1Score" Padding="5" Grid.Row="1" HorizontalAlignment="Right" Text="Score :" FontSize="12" FontFamily="Showcard Gothic" Foreground="#FFEBF409"/></Grid></DataTemplate>

From that datatemplate, I would like to get my text box beeing displayed smoothly by triggering opacity with storyboard for instance.

The problem that I have is to identify on which DataTemplate trigger I should start a storyboard which will change TextBloc opacity from 0 to 1 ?

Thnaks for help and sample

regards

serge


Your knowledge is enhanced by that of others.

How to select/deselect all check boxes in a given Groupbox at once

$
0
0

Hi,

I have a WPF form like the one given below. My requirement is upon clicking select all/ unselect all (ContextMenu) i want to check all the check boxes inside the group boxes. I didn't find a smart way of doing this yet. Hope you guys can help. thankx!

Apply tooltip style in ErrorTemplate

$
0
0

I have a custom style for ErrorTemplate tooltips. This works just fine when applied to a control.

<Style x:Key="errorToolTip" TargetType="{x:Type ToolTip}"><...></Style>

I then have the following ErrorTemplate.

<Style x:Key="errorStyle" TargetType="{x:Type Control}"><Setter Property="Validation.ErrorTemplate"><Setter.Value><ControlTemplate><DockPanel><Image Width="16" Height="16" DockPanel.Dock="Right" Margin="3,0,0,0"
							Source="Warning_16x16_72.png"/><Border BorderBrush="Red" BorderThickness="2" CornerRadius="2" Background="{x:Null}"><AdornedElementPlaceholder/></Border></DockPanel></ControlTemplate></Setter.Value></Setter><Style.Triggers><Trigger Property="Validation.HasError" Value="true"><Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},
				Path=(Validation.Errors)[0].ErrorContent}"/></Trigger></Style.Triggers></Style><Style TargetType="TextBox" BasedOn="{StaticResource errorStyle}" /><Style TargetType="CheckBox" BasedOn="{StaticResource errorStyle}" /><Style TargetType="ComboBox" BasedOn="{StaticResource errorStyle}" />
How do I apply the errorToolTip static resource to the error template?

Bind XML File to TreeView control and filter using XPath

$
0
0

Given the following XML how can I specify an XPath which will populate the TreeView control with every node element EXCEPTwhere Name="Main Heading"

I dont want the root node to be displayed, just need SubHeading and its children and Type3 and its children

Xml File:

<node type="Main heading" Name="Main heading"><node type="Sub Heading" Name="Sub Heading"><node type="Type1" Name="Type1"><node type="Type1" Name="Type1"/><node type="Type1" Name="Type1"/></node><node type="Type2" Name="Type2"><node type="Type1" Name="Type1"/><node type="Type2" Name="Type2"/></node></node><node type="Type3" Name="Type3"><node type="Type3" Name="Type3"></node></node></node>

XAML:

<Window x:Class="TreeView.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:TreeView"
        Title="MainWindow" Height="350" Width="525"><Window.DataContext><local:MainViewModel /></Window.DataContext><Window.Resources><HierarchicalDataTemplate x:Key="template"><TextBlock x:Name="tb" Text="{Binding XPath='@Name'}" /><HierarchicalDataTemplate.ItemsSource><Binding XPath="node" /></HierarchicalDataTemplate.ItemsSource></HierarchicalDataTemplate></Window.Resources><Grid><TreeView ItemsSource="{Binding XmlSource}" ItemTemplate="{StaticResource template}"></TreeView></Grid></Window>

ViewModel:
    public class MainViewModel
    {
        public XmlDocument XmlSource { get; set; }

        public MainViewModel()
        {
            XmlSource = new XmlDocument();
            XmlSource.Load("Books.xml");
        }
    }


ProgressBar not get Proper grid using MultiBinding Converter in .Net Framework 4.0

$
0
0

Hi,

  I have Migrated from .net Framework 3.5 to .net Framework 4.0

After that I am facing the ProgressBar problem.

In my application in .net Framework 4.0 I am using MultiBinding Converter as follows,

In following converter I am not getting the respective Grid in currGrid which is getting me proper in .net Framework 3.5 as currGrid=progressGrid which is expected.

So how I can overcome from this problem in .net Framework 4.0

How I can get currGrid as progressGrid like in .net Framework 3.5

I want to fill that grid as progress value increases as follows,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Globalization;

namespace MultiBindingConverter
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public double _val = 0;
        public MainWindow()
        {
            InitializeComponent();
            for (int i = 0; i <= 100; i++)
            {
                _val=_val+10;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }
    }

    public class ProgressBarBrushConverter : IMultiValueConverter
    {
        public double _value = 100;
        DispatcherTimer tm;
        Grid currGrid = new Grid();
        Brush myGray = new SolidColorBrush(Color.FromRgb(157, 163, 165));
        Brush myGreen = new SolidColorBrush(Color.FromRgb(124, 241, 183));


        // Methods
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                if (values != null && values.Length > 2)
                {
                    double value = (double)values[0];
                    bool bIsIndeterminate = (bool)values[1];
                    double maxValue = (double)values[2];
                    double minValue = (double)values[3];currGrid = values[4] as Grid;
                    System.Windows.Visibility visible = (System.Windows.Visibility)values[5];

                    if (visible != System.Windows.Visibility.Visible)
                    {
                        if (tm != null && tm.IsEnabled)
                            tm.Stop();
                    }
                    else
                    {

                        if (bIsIndeterminate)
                        {
                            if (tm == null)
                            {
                                tm = new DispatcherTimer();
                                tm.Tick += new EventHandler(tm_Tick);
                                tm.Interval = new TimeSpan(1000000);
                            }
                            tm.Start();
                        }
                        else
                        {
                            if (tm != null && tm.IsEnabled)
                                tm.Stop();

                            if (maxValue <= 0)
                                maxValue = 100;

                            int SectorNumber = (int)Math.Ceiling(value / ((maxValue - minValue) / 10));

                            for (int i = 0; i < currGrid.Children.Count; i++)
                            {
                                Object myRect = currGrid.Children[i];

                                if (myRect.GetType() == typeof(Rectangle))
                                {
                                    Rectangle rect = myRect as Rectangle;

                                    if (i < SectorNumber)
                                        rect.Fill = myGreen;
                                    else
                                        rect.Fill = myGray;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                if (tm != null && tm.IsEnabled)
                    tm.Stop();

                return Brushes.White;
            }

            return Brushes.White;
        }

        void tm_Tick(object sender, EventArgs e)
        {
            int iGreenIndex = -1;

            for (int i = 0; i < currGrid.Children.Count; i++)
            {
                Object myRect = currGrid.Children[i];

                if (myRect.GetType() == typeof(Rectangle))
                {
                    Rectangle rect = myRect as Rectangle;
                    if (rect.Fill == myGreen)
                    {
                        iGreenIndex = i;
                        rect.Fill = myGray;
                        break;
                    }
                }
            }

            if (iGreenIndex == -1)
                (currGrid.Children[0] as Rectangle).Fill = myGreen;
            else
            {
                if (iGreenIndex + 1 < currGrid.Children.Count)
                {
                    if (currGrid.Children[iGreenIndex + 1].GetType() == typeof(Rectangle))
                        (currGrid.Children[iGreenIndex + 1] as Rectangle).Fill = myGreen;
                }
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

}


<Window x:Class="MultiBindingConverter.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"
        xmlns:local="clr-namespace:MultiBindingConverter"><Window.Resources><ResourceDictionary Source="Controls.xaml"/></Window.Resources><StackPanel><Button Content="Progress" Width="72" Height="21" Click="Button_Click"></Button><ProgressBar Width="250" Height="20" Value="10"></ProgressBar></StackPanel></Window>

and Have ResourceDictionary as follows,

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:MultiBindingConverter"><Style TargetType="{x:Type ProgressBar}" ><Setter Property="BorderThickness" Value="1"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ProgressBar}" ><Grid x:Name="parent1"><Border x:Name="PART_Track"><Grid x:Name="parent2"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><!--<ColumnDefinition Width="35"/>--></Grid.ColumnDefinitions><Grid  x:Name="parent"><Grid Grid.Column="0" x:Name="progressGrid"><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="0"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="1"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="2"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="3"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="4"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="5"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="6"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="7"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="8"/><Rectangle Stroke="#42B642" StrokeThickness="1" Grid.Column="9"/><Grid.Background><MultiBinding><MultiBinding.Converter><local:ProgressBarBrushConverter /></MultiBinding.Converter><MultiBinding.ConverterParameter>1</MultiBinding.ConverterParameter><Binding Path="Value" RelativeSource="{RelativeSource TemplatedParent}"/><Binding Path="IsIndeterminate" RelativeSource="{RelativeSource TemplatedParent}"/><Binding Path="Maximum" RelativeSource="{RelativeSource TemplatedParent}"/><Binding Path="Minimum" RelativeSource="{RelativeSource TemplatedParent}"/><Binding ElementName="progressGrid" /><Binding Path="Visibility" RelativeSource="{RelativeSource TemplatedParent}"/><!--<Binding ElementName="txtShowValue" />--></MultiBinding></Grid.Background></Grid></Grid></Grid></Border></Grid></ControlTemplate></Setter.Value></Setter></Style></ResourceDictionary>

How to use WPF SplashScreen class under .NET Framework 4.5 / Windows 8?

$
0
0
Hi,

I have a problem using the WPF SplashScreen class under Windows 8:
When shutting down the application while the splash screen is about to be displayed, the program crashes sporadically with the following call stack:
ChildEBP RetAddr  
010af7c8 749eeaeb KERNELBASE!RaiseException+0x6c
010af7e4 74acb6e4 clr!COMPlusThrowBoot+0x1a
010af7f0 747d2823 clr!UMThunkStubRareDisableWorker+0x25
010af818 751d77d8 clr!UMThunkStubRareDisable+0x9
010af844 751d78cb USER32!InternalCallWinProc+0x23
010af8c0 751d7b6f USER32!UserCallWinProcCheckWow+0x100
010af924 751d7c44 USER32!DispatchClientMessage+0x15d
010af960 77962f02 USER32!__fnDWORD+0x2b
010af974 018541a0 ntdll!KiUserCallbackDispatcher+0x2e
WARNING: Frame IP not in any known module. Following frames may be wrong.
010af9c8 7693ddf8 0x18541a0
010afa18 7693e02a combase!CCliModalLoop::MyPeekMessage+0x5f [d:\win8_gdr\com\combase\dcomrem\callctrl.cxx @ 2316]
010afa8c 7693e0ca combase!CCliModalLoop::HandleWakeForMsg+0x15a [d:\win8_gdr\com\combase\dcomrem\callctrl.cxx @ 1954]
010afadc 76938d8d combase!CCliModalLoop::BlockFn+0x25b [d:\win8_gdr\com\combase\dcomrem\callctrl.cxx @ 1618]
010afb88 76938c23 combase!ClassicSTAThreadWaitForHandles+0xd7 [d:\win8_gdr\com\combase\dcomrem\classicsta.cpp @ 46]
010afbb0 748b3e82 combase!CoWaitForMultipleHandles+0xa4 [d:\win8_gdr\com\combase\dcomrem\sync.cxx @ 120]
010afc08 748b3e27 clr!MsgWaitHelper+0x64
010afc94 7494e825 clr!Thread::DoAppropriateWaitWorker+0x224
010afd00 7494e984 clr!Thread::DoAppropriateWait+0x64
010afd4c 74852f14 clr!CLREventBase::WaitEx+0x128
010afd64 749823f0 clr!CLREventBase::Wait+0x1a
010afde0 7498243d clr!IsRuntimeStarted+0xab
010afdec 749825e4 clr!WaitForEndOfShutdown+0x1b
010afe30 74945611 clr!EEShutDown+0xd1
010afe3c 7494566e clr!DisableRuntime+0x118
010afe50 74921fc2 clr!EEPolicy::HandleExitProcess+0x50
010afe90 74924162 clr!_CorExeMainInternal+0x1b1
010afecc 74e7f5a3 clr!_CorExeMain+0x4d
010aff04 74ef7efd mscoreei!_CorExeMain+0x10a
010aff1c 74ef4de3 MSCOREE!ShellShim__CorExeMain+0x7d
010aff24 74ff8543 MSCOREE!_CorExeMain_Exported+0x8
010aff30 7797ac69 KERNEL32!BaseThreadInitThunk+0xe
010aff74 7797ac3c ntdll!__RtlUserThreadStart+0x72
010aff8c 00000000 ntdll!_RtlUserThreadStart+0x1b
The crash does not happen all the time, only every now and then.

Here a simple example program to reproduce the problem:

App.xaml.cs file:
using System;
using System.Threading;
using System.Windows;

namespace SplashScreenTest
{
    public partial class App : Application
    {
        private void App_Startup(object sender, StartupEventArgs e)
        {
            SplashScreen splash = new SplashScreen("Splash.png");
            splash.Show(false);

            Thread.Sleep(1000);

            splash.Close(new TimeSpan(0,0,0,3));
            this.Shutdown();
        }
    }
}

App.xaml file:
<Application x:Class="SplashScreenTest.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Startup="App_Startup"><Application.Resources></Application.Resources></Application>

You can use any PNG file as Splash.png.

Is there anything wrong in the way I am using the SplashScreen class?

(Please note: the crash does not happen if the timespan is reduced to zero; this can be used as a workaround. But still, a crash should not happen with a non-zero timespan.)

PropertyChanged not fired when user control's combo box selected value changes

$
0
0

I have a user control with a combo box and a text box as shown below.

<UserControl.Template><ControlTemplate TargetType="{x:Type UserControl}"><DockPanel LastChildFill="True"><TextBlock DockPanel.Dock="Left" Text="{TemplateBinding local:ctlCombobox.LabelText}" Width="{TemplateBinding local:ctlCombobox.LabelWidth}" TextAlignment="Right" Padding="0,0,3,0" VerticalAlignment="Center"/><ComboBox 
                    ItemsSource="{TemplateBinding local:ctlCombobox.ItemsSource}"
                    DisplayMemberPath="{TemplateBinding local:ctlCombobox.DisplayMemberPath}"
                    SelectedValue="{TemplateBinding local:ctlCombobox.SelectedValue}"
                    SelectedValuePath="{TemplateBinding local:ctlCombobox.SelectedValuePath}"/></DockPanel></ControlTemplate></UserControl.Template>

and the corresponding .cs file snippet as follows

   public static readonly DependencyProperty DisplayMemberPathProperty = DependencyProperty.Register("DisplayMemberPath", typeof(string), typeof(ctlCombobox), new FrameworkPropertyMetadata() { BindsTwoWayByDefault = true });  
        public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(ctlCombobox), new FrameworkPropertyMetadata() { BindsTwoWayByDefault = true });
        public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.Register("SelectedIndex", typeof(int), typeof(ctlCombobox), new FrameworkPropertyMetadata() { BindsTwoWayByDefault = true });
        public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(object), typeof(ctlCombobox), new FrameworkPropertyMetadata() { BindsTwoWayByDefault = true });
        public static readonly DependencyProperty SelectedValuePathProperty = DependencyProperty.Register("SelectedValuePath", typeof(string), typeof(ctlCombobox), new FrameworkPropertyMetadata() { BindsTwoWayByDefault = true });
        public static readonly DependencyProperty SelectedValueProperty = DependencyProperty.Register("SelectedValue", typeof(object), typeof(ctlCombobox), new FrameworkPropertyMetadata() { BindsTwoWayByDefault = true, DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });

		#endregion Fields 

		#region Constructors (1) 

        public ctlCombobox()
        {
            InitializeComponent();
        }

		#endregion Constructors 

		#region Properties (10) 

        [Browsable(true)]
        public string DisplayMemberPath
        {
            get { return (string)GetValue(DisplayMemberPathProperty); }
            set { SetValue(DisplayMemberPathProperty, value); }
        }

        

        public IEnumerable ItemsSource
        {
            get { return (IEnumerable)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }
        [Browsable(true)]
        public int SelectedIndex
        {
            get { return (int)GetValue(SelectedIndexProperty); }
            set { SetValue(SelectedIndexProperty, value); }
        }

        [Browsable(true)]
        public object SelectedItem
        {
            get { return (object)GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        [Browsable(true)]
        public object SelectedValue
        {
            get { return (object)GetValue(SelectedValueProperty); }
            set { SetValue(SelectedValueProperty, value); }
        }

        [Browsable(true)]
        public string SelectedValuePath
        {
            get { return (string)GetValue(SelectedValuePathProperty); }
            set { SetValue(SelectedValuePathProperty, value); }
        }

This user control is used in my main window as follows:

<cc:ctlCombobox x:Name="cmbEmployeeType" DisplayMemberPath="Name" SelectedValuePath="Id" 
                                SelectedValue="{Binding Path=EmployeeTypeId, Mode=TwoWay}"
                                ItemsSource="{Binding Source={x:Reference ctl}, Path=DataContext.EmployeeTypes}" Width="250" Grid.Row="0" Grid.Column="0" 
                                VerticalAlignment="Center" HorizontalAlignment="Left"></cc:ctlCombobox


The property changed event is fired on EmployeeTypeId when the form is loaded, however, it is not fired when I select another value in the combo box. Additionally, the property change event fires perfectly whenever I use the default WPF combobox. 

Search Graphic Library WPF C#

$
0
0

Hi,

I want a DLL, who allow create a line Graphic with a zoom, same VisiBlox but this isn't free. I want free library.

Thanks, it's urgent!!!

MVVM design pattern for beginner in WPF

$
0
0

Click here To View The Content

here I used to explain MVVM core functions what do you think about that ?

Please use Firefox or Chrome to view the content.I think you will  get good practical understand if you are beginner.

Viewing all 18858 articles
Browse latest View live


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