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

How get barcode reader value in TextBox

$
0
0

Hello,

How to get barcode reader value in TextBox.


Runtime binding change + unexpected event firing issue WPF

$
0
0

I change binding at runtime with datatriggers in XAML like this:

<ToggleButton Checked="MinSyncX_OnChecked" Unchecked="MinSyncX_OnUnchecked" TargetUpdated="FrameworkElement_OnTargetUpdated"
                                        Tag="{Binding Path=CameraViewDirection, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                        ToolTip="{Binding Source={StaticResource CameraLocalization}, Path=ToolTips.SyncX, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"><ToggleButton.Style><Style TargetType="ToggleButton" BasedOn="{StaticResource CameraSyncCommonStyle}"><Style.Triggers><DataTrigger Binding="{Binding Path=CameraViewDirection.Limitations.UI.SelectedLimitation.W, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="0"><Setter Property="IsEnabled" Value="{Binding Path=CameraViewDirection.Limitations.UI.IsMinTripleEnabled.X, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"></Setter><Setter Property="IsChecked" Value="{Binding Path=CameraViewDirection.Limitations.UI.IsMinTripleChecked.X, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></Setter></DataTrigger><DataTrigger Binding="{Binding Path=CameraViewDirection.Limitations.UI.SelectedLimitation.W, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="1"><Setter Property="IsEnabled" Value="{Binding Path=CameraViewDirection.Limitations.UI.IsMaxTripleEnabled.X, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"></Setter><Setter Property="IsChecked" Value="{Binding Path=CameraViewDirection.Limitations.UI.IsMaxTripleChecked.X, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></Setter></DataTrigger><DataTrigger Binding="{Binding Path=CameraViewDirection.Limitations.UI.SelectedLimitation.W, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="2"><Setter Property="IsEnabled" Value="{Binding Path=CameraViewDirection.Limitations.UI.IsBothTripleEnabled.X, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"></Setter><Setter Property="IsChecked" Value="{Binding Path=CameraViewDirection.Limitations.UI.IsBothTripleChecked.X, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></Setter></DataTrigger></Style.Triggers></Style></ToggleButton.Style><ToggleButton.Content><Image Source="{Binding Source={StaticResource CameraIcons}, Path=XAxis, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"></Image></ToggleButton.Content></ToggleButton>

Everything seems fine - binding really changes, but I have one issue which I don`t know how to solve: When binding changed, MinSyncX_OnUnchecked event firing even if binded value is true which means that ToggleButton must stays checked after binding change. Firing of this event during binding switching braked my code, so I wish to now how to suppress this event during binding change if IsChecked property must be set to true.

A little tricky, but I hope you will understand my problem.

Edit

One thing I noticed that unchecked event ALWAYS fired if data trigger value switched to the first in list. Even it has a value=1 or value=2. Does this by design or it can be fixed somehow?


How to Merge cells in gridView columns following mvvm.

$
0
0

Hello, 

I have an app (following mvvm pattern) with columns as

Left ColumnRight Column
1
12
21
22
31
32

These columns resides in gridview which has Listview as the root. Is there any way i can merge the left column values to single values. 

Thanks.


Calling Class property in Resource XAML gives error

$
0
0
I have written code to attach a property Mask.But iam getting the error

Cannot resolve the Style Property 'Marsk'. Verify that the owning type is the Style's TargetType, or use Class.Property syntax to specify the Property.)

 

public static MaskType GetMask(DependencyObject obj)
        {
            return (MaskType)obj.GetValue(MaskProperty);
        }

        public static void SetMask(DependencyObject obj, MaskType value)
        {
            obj.SetValue(MaskProperty, value);
        }

        public static readonly DependencyProperty MaskProperty =
            DependencyProperty.RegisterAttached(
                "Mask",
                typeof(MaskType),
                typeof(pMaskableTextBox),
                new FrameworkPropertyMetadata(MaskChangedCallback)
                );

        private static void MaskChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue is TextBox)
            {
                (e.OldValue as TextBox).PreviewTextInput -= TextBox_PreviewTextInput;
                DataObject.RemovePastingHandler((e.OldValue as TextBox), (DataObjectPastingEventHandler)TextBoxPastingEventHandler);
            }

            TextBox _this = (d as TextBox);
            if (_this == null)
                return;

            if ((MaskType)e.NewValue != MaskType.Any)
            {
                _this.PreviewTextInput += TextBox_PreviewTextInput;
                DataObject.AddPastingHandler(_this, (DataObjectPastingEventHandler)TextBoxPastingEventHandler);
            }

            ValidateTextBox(_this);
        }

i have called this property in styles rStyles.XAML

 xmlns:pBasePage="clr-namespace:Parts.Pages.Page;assembly=Parts.Pages.Page"


<Style x:Key="styDecimalTextBox" TargetType="{x:Type TextBox}">

        <Setter Property="pBasePage:Parts.Pages.Page.pMaskableTextBox.Mask" Value ="Decimal"  />
</Style>


How can I limit the fonts in the Character Map (charmap) and reinitialize the state after use?

$
0
0

            In a WPF application I have a RichTextBox in which users will be inserting text. I also must give the user the ability to insert characters. To do so I have called up charmap.exe using

           Process charProcess = new Process();

           ProcessStartInfo startInfo = new ProcessStartInfo();

           charProcess.StartInfo.FileName = strCharmap;

           charProcess.Start();

etc., and it works fine. There are several problems I have basically with charmap, however, not with WPF. The first is that because of the subsequent use of the user’s insertion in the RTB, I must restrict the font to “Ariel Unicode MS.”  So far all I have been able to do is instruct and warn the user not to change fonts and change back any font change that occurs as a result of use of “Advanced view” features.

           Question number one is, how can I restrict the fonts loaded into charmap to this one font? The second problem is that if another font is called up, or the “Advanced view” state of charmap is closed, or a “Group by” feature is opened, these choices will be retained for the next user that opens charmap. How can I initialize the state of charmap for each new user with the correct font and “Advanced view” features showing. It is said,but in old posts, that reinitialization occurs for all but administrative users, but this seems to be no longer true. I have tried permission changes in charmap’s Properties, but I can’t get the necessary reinitialization to occur even if user’s don’t have modify permission. Can one use a .ini file, or the .mui file, or make Registry changes to accomplish my goals. There seems to be a warning in the .mui file about changing fonts, but is it cancelled? Whatever I have to do, does it get done in the code behind or do I have to modify the Windows OS and files. I am using Windows 7 and C#.

           I have looked at other character maps but they are either too complicated for the casual user, or they have no search engine and advanced features, or they have the same problems.

           I am somewhat a novice with respect to the Windows files use and WPF, so please be fairly clear, complete, and prescriptive in your answer. Also so that I and others can learn, it would be nice to have an explanation of why one does whatever you suggest. Your help is appreciated.

Dynamic Data Display Getting Started

$
0
0

Hi,

I downloaded DynamicDataDisplay.dll and added to my WPF project's references. Then I added the simple code that is shown on https://dynamicdatadisplay.codeplex.com/ home page

linegraph.Plot(x,y); // x and y are IEnumerable<double> 
to cs file

and the Xaml code 

<d3:ChartBottomTitle="Argument"LeftTitle="Function"><d3:LineGraphx:Name="linegraph"Description="Simple linegraph"Stroke="Blue"StrokeThickness="3"/></d3:Chart>

Then I get the error that says 

"The name "Chart" does not exist in the namespace "

What could be the problem? I couldn't even get started.

Animating an AttachedProperty causes slider control to stop working

$
0
0

I have a small app that I am using to try and tame the Volume property of the MediaElement.

The real app that I need to fix is a media player app but it has so much code/XAML I am using the "test" app to ensure that things will work before putting the code into it.

First the XAML:

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:BindingToAttachedProperty"
    Title="MainWindow" Height="350" Width="525"><Grid local:AttachedProperties.AllVolume=".5" x:Name="theGrid"><Grid.RowDefinitions><RowDefinition Height="Auto"></RowDefinition><RowDefinition></RowDefinition></Grid.RowDefinitions><StackPanel Orientation="Horizontal" Grid.Row="0" ><Slider Value="{Binding ElementName=theGrid , Path=(local:AttachedProperties.AllVolume),Mode=TwoWay }" Maximum="1" Width="200" LargeChange="0.1" TickFrequency="0.1"></Slider><Button x:Name="theButton" Click="theButton_Click" Margin="20,0,0,0">Go Up</Button><Button x:Name="theDButton" Click="theDButton_Click" Margin="20,0,0,0">Go Up</Button><TextBlock Text="{Binding ElementName=theGrid , Path=(local:AttachedProperties.AllVolume)}" Grid.Row="1" Margin="20,0,0,0"></TextBlock></StackPanel><MediaElement x:Name="theMedia" Grid.Row="1" Volume="{Binding ElementName=theGrid , Path=(local:AttachedProperties.AllVolume)}" Source="H:\Movies\Frozen.mp4"></MediaElement></Grid></Window>

Now in the sample app I have only one MediaElement (the real app has two and I am using a volume change on each to achieve a crossover effect.  The sample app is using an AttachedProperty to bind to the volume.  This works as expected although VS 2013 has a hard time with the binding expression.  (one would have thought by this iteration of VS it would deal with all bindings).  If I start the app and using the slider it does in fact modify the volume of the MediaElement.

As I said above I am using two MediaElements to achieve crossover so when that happens there are two animations running, one to raise the volume of the new mp3 (the sample uses a .mp4 file but that is not the problem) and one to decrease the already playing mp3.

Now in the sample app I have two buttons which I am using  to simulate the ending of the media.

The Code Behind:

Imports System.ComponentModel
Imports System.Windows.Media.Animation

Class MainWindow

    Private Sub theButton_Click(sender As Object, e As RoutedEventArgs)
        Dim sb As New Storyboard
        Dim da As New DoubleAnimation With {.From = theMedia.Volume, .To = 1.0, .Duration = TimeSpan.FromSeconds(10)}
        Storyboard.SetTarget(da, theGrid)
        Storyboard.SetTargetProperty(da, New PropertyPath(AttachedProperties.AllVolumeProperty))
        sb.Children.Add(da)
        sb.Begin(Me, True)

    End Sub

    Private Sub theDButton_Click(sender As Object, e As RoutedEventArgs)
        Dim sb As New Storyboard
        Dim da As New DoubleAnimation With {.From = theMedia.Volume, .To = 0.0, .Duration = TimeSpan.FromSeconds(10)}
        Storyboard.SetTarget(da, theGrid)
        Storyboard.SetTargetProperty(da, New PropertyPath(AttachedProperties.AllVolumeProperty))
        sb.Children.Add(da)
        sb.Begin(Me, True)
    End Sub
End Class

One button makes the volume go to 1.0 and the other makes it decrease to 0.0.  Both buttons work.

Now the problem arises - once the animation (either one) happens the slider goes inactive.  I have checked with Snoop and the slider is still enabled but you can no longer drag the thumb of the slider.  The two animations of the volume still work so the binding is still there and the textblock and the slider values change with the animation.

Anyone have an idea why the slider seems to go inactive?


Lloyd Sheen

Get Cursor Postion in Access Text Box using VBA

$
0
0

I want to be able to find the position of the Cursor inside a Text Box control using Access VBA.

What I have in mind is to be able to insert standard text phrases into existing text inside a Text Box, buy first putting an insertion point into the text by clicking in the Text Box Control.  I then intend to have a Combo Box preloaded with standard phrases that can then be inserted at the insertion point in the Test Box, simply by selecting them from the Combo Box.

It's pretty easy to add them at the start of the existing text, but how do I do it somewhere in the middle?


Set UserControl's dependency property during design-time

$
0
0

Hi,

Is there a way to set the design-time value of a UserControl's dependency property? Not when I'm using this UserControl, on a Page, or something but when I actually designing the control. (I would prefer not set the property's default value, for design data)

Here is a sample code:

public partial class MyControl : UserControl
{public string MyProperty
	{get { return (string)GetValue(MyPropertyProperty); }set { SetValue(MyPropertyProperty, value); }
	}public static readonly DependencyProperty MyPropertyProperty =DependencyProperty.Register("MyProperty"typeof(string), typeof(MyControl), new PropertyMetadata("", MyPropertyChanged));private static void MyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
	{// do some parsing magic here, and distribute the results into the controls
		(d as MyControl).tb1.Text = res1;
		(d as MyControl).tb2.Text = res2;
		(d as MyControl).tb3.Text = res3;
	}public MyControl()
	{
		InitializeComponent();if (WpfHelper.IsInDesignMode)
		{
			MyProperty = "Some complex string data...";	// this isn't works on the UserControl's design view
		}
	}
}

And the XAML file

<UserControl x:Class="st.Reader.UI.Controls.MyControl"             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"              MyProperty="some design data" (<- I would like to do something like this)             d:DesignHeight="300" d:DesignWidth="300">    <Grid>        <Grid.RowDefinitions>            <RowDefinition Height="*"/>            <RowDefinition Height="*"/>            <RowDefinition Height="*"/>        </Grid.RowDefinitions>        <TextBlock x:Name="tb1" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top"><Run Text="TextBlock"/></TextBlock>        <TextBlock x:Name="tb2" TextWrapping="Wrap" Grid.Row="1"><Run Text="TextBlock"/></TextBlock>        <TextBlock x:Name="tb3" TextWrapping="Wrap" Text="TextBlock" Grid.Row="2"/>    </Grid></UserControl>

Thx

Export DataGrid to excel with formatting VB.net WPF

$
0
0

Hi all

I was able to run code for exporting DataGridView to excel in VB.net desktop application. Now, I would like to do this in WPF desktop application with DataGrid. 

I'm using this code:

Dim xlApp As Excel.Application = New Excel.Application
            Dim xlWorkBook As Excel.Workbook
            Dim xlWorkSheet As Excel.Worksheet
            Dim misValue As Object = System.Reflection.Missing.Value

            xlWorkBook = xlApp.Workbooks.Add(misValue)
            xlWorkSheet = DirectCast(xlWorkBook.Sheets("sheet1"), Excel.Worksheet)

            'xlApp.Visible = True

            Dim headers = (From ch In GeneralReport.Columns _
                            Let header = DirectCast(DirectCast(ch, DataGridViewColumn).HeaderCell, DataGridViewColumnHeaderCell) _
                            Select header.Value).ToArray()
            Dim headerText() As String = Array.ConvertAll(headers, Function(v) v.ToString)

            Dim items() = (From r In GeneralReport.Rows _
                    Let row = DirectCast(r, DataGridViewRow) _
                    Where Not row.IsNewRow _
                    Select (From cell In row.Cells _
                        Let c = DirectCast(cell, DataGridViewCell) _
                        Select c.Value).ToArray()).ToArray()

            Dim table As String = String.Join(vbTab, headerText) & Environment.NewLine
            For Each a In items
                Dim t() As String = Array.ConvertAll(a, Function(v) v.ToString)
                table &= String.Join(vbTab, t) & Environment.NewLine
            Next
            table = table.TrimEnd(CChar(Environment.NewLine))
            Clipboard.SetText(table)

            Dim alphabet() As Char = "abcdefghijklmnopqrstuvwxyz".ToUpper.ToCharArray
            Dim range As Excel.Range = xlWorkSheet.Range("A1:" & alphabet(headerText.Length - 1) & (items.Length + 1).ToString)
            Try
                xlWorkSheet.Columns.AutoFit()
                range.Select()
                'range.Copy()
                xlWorkSheet.Paste()
            Catch ex As Exception
                MessageBox.Show("Exception " + ex.Message)
            Finally
                GC.Collect()
            End Try
            range.Borders(Excel.XlBordersIndex.xlDiagonalDown).LineStyle = Excel.XlLineStyle.xlLineStyleNone
            range.Borders(Excel.XlBordersIndex.xlDiagonalUp).LineStyle = Excel.XlLineStyle.xlLineStyleNone
            With range.Borders(Excel.XlBordersIndex.xlEdgeLeft)
                .LineStyle = Excel.XlLineStyle.xlContinuous
                .ColorIndex = 24 'black
                .TintAndShade = 0
                .Weight = Excel.XlBorderWeight.xlThick
            End With
            With range.Borders(Excel.XlBordersIndex.xlEdgeTop)
                .LineStyle = Excel.XlLineStyle.xlContinuous
                .ColorIndex = 24 'black
                .TintAndShade = 0
                .Weight = Excel.XlBorderWeight.xlMedium
            End With
            With range.Borders(Excel.XlBordersIndex.xlEdgeBottom)
                .LineStyle = Excel.XlLineStyle.xlContinuous
                .ColorIndex = 24 'black
                .TintAndShade = 0
                .Weight = Excel.XlBorderWeight.xlMedium
            End With
            With range.Borders(Excel.XlBordersIndex.xlEdgeRight)
                .LineStyle = Excel.XlLineStyle.xlContinuous
                .ColorIndex = 24 'black
                .TintAndShade = 0
                .Weight = Excel.XlBorderWeight.xlMedium
            End With
            With range.Borders(Excel.XlBordersIndex.xlInsideVertical)
                .LineStyle = Excel.XlLineStyle.xlContinuous
                .ColorIndex = 24 'black
                .TintAndShade = 0
                .Weight = Excel.XlBorderWeight.xlThin
            End With
            With range.Borders(Excel.XlBordersIndex.xlInsideHorizontal)
                .LineStyle = Excel.XlLineStyle.xlContinuous
                .ColorIndex = 24 'black
                .TintAndShade = 0
                .Weight = Excel.XlBorderWeight.xlThin
            End With
            'With range.Interior
            '    .Pattern = Excel.XlPattern.xlPatternLinearGradient
            '    .Gradient.Degree = 60
            '    .Gradient.ColorStops.Clear()
            '    With .Gradient.ColorStops.Add(0)
            '        .ThemeColor = Excel.XlThemeColor.xlThemeColorAccent1
            '        .TintAndShade = 0
            '    End With
            'End With
            Dim arry As Object(,)
            arry = range.Value
            For r As Integer = 1 To arry.GetUpperBound(0)
                For c As Integer = 1 To arry.GetUpperBound(1)
                    Dim myRange As Object = arry(r, c)
                Next c
            Next r
            Dim SourceRange As Excel.Range = DirectCast(xlWorkSheet.UsedRange, Excel.Range)
            FormatAsTable(SourceRange, "Table1", "TableStyleMedium2")
            'range.Select()
            'range.ListObjects("Table1").TableStyle = "TableStyleLight2"
            If Not Directory.Exists("C:\Timer Tool Reports\") Then
                Directory.CreateDirectory("C:\Timer Tool Reports\")
            End If
            Dim dat As String = dtReport.Value.ToString("dd-MM-yyyy")
            Try
                xlWorkBook.SaveAs("C:\Timer Tool Reports\" & pathN & "_" & dat & ".xlsx") 'save our workbook
                MsgBox("You can find the file C:\Timer Tool Reports\" & pathN & ".xlsx")
            Catch ex As Exception
                MessageBox.Show("Exception " + ex.Message)
            Finally
                GC.Collect()
            End Try
            'releasing object references
            xlWorkBook = Nothing
            xlWorkBook = Nothing
            xlApp.Quit()
            xlApp = Nothing
            releaseObject(xlApp)
            releaseObject(xlWorkBook)
            releaseObject(xlWorkSheet)
            Clipboard.Clear()
            Dim proc As System.Diagnostics.Process
            For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
                proc.Kill()
            Next
        End If

    Public Sub FormatAsTable(SourceRange As Excel.Range, TableName As String, TableStyleName As String)
        SourceRange.Worksheet.ListObjects.Add(Excel.XlListObjectSourceType.xlSrcRange, SourceRange, System.Type.Missing, Excel.XlYesNoGuess.xlYes, System.Type.Missing).Name = TableName
        SourceRange.[Select]()
        SourceRange.Worksheet.ListObjects(TableName).TableStyle = TableStyleName
    End Sub

Is it possible to use this code in WPF? When I'm trying to implement it I get error in:

        Dim headers = (From ch In GeneralReport.Columns _
                        Let header = DirectCast(DirectCast(ch, DataGridViewColumn).HeaderCell, DataGridViewColumnHeaderCell) _
                        Select header.Value).ToArray()
        Dim headerText() As String = Array.ConvertAll(headers, Function(v) v.ToString)

        Dim items() = (From r In GeneralReport.Rows _
                Let row = DirectCast(r, DataGridViewRow) _
                Where Not row.IsNewRow _
                Select (From cell In row.Cells _
                    Let c = DirectCast(cell, DataGridViewCell) _
                    Select c.Value).ToArray()).ToArray()

I have no idea how to change unsupported members.

Thank you for your support.


Mathh

Change active window titlebar color

$
0
0

Hi,

I have build custom titlebar and I have fixed color for that titlebar.

Now, I want to change the titlebar color e.g like in windows when you click on window then color of titlebar is getting changed to blue and other windows titlbar are changing to gray. How to achieve this.


Vipul Mistry Sr. Embedded Engineer www.eInfochips.com

Problem With ComboBox Selection Changed Event

$
0
0

I need a code In WPF  that can bemodified text ComboBox inSelected Changeevent
to raise output., But at run time,change the text before it issent to the output. Please help me

من به کدی احتیاج دارم که بتواند متن انتخاب شده توسط کمبو باکس را در خروجی نمایش دهد . اما در هنگام استفاده از رویداد تغییر انتخاب ، متن قبل از تغییر به خروجی فرستاده میشود . لطفا کمک کنید .

I need to have the equivalent of this code in WPF DataGrid.Rows[ComboBox.SelectedIndex].Selected = true;

$
0
0

My Code in C#

 private void ComboBoxSelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbGorooAsli.SelectedIndex >= 0)
            {
                DataGrid.Rows[ComboBox.SelectedIndex].Selected = true;
            }
        }

 I need to have the equivalent of this code in WPF

User Control with combobox

$
0
0

I created a UserControl with TextBlock, TextBox and ComboBox

I have MainWindow with TabControl and this tabcontrol has several UserControls, one UserControl per TabItem

The UserControls in TabItems have the custom UserContol that I created.

Everything is working fine except the ComboBox, the ComboBox fills with data items and SelectedValue, but when I switch tabs on the MainWindow the Property that's bond to the SelectedValue gets set to null value and I can not figure out what is passing the null value, I put a break point inside the ComboBox SelectedValue setter property and the value shows null when the program hits the break point, but when I try to continue stepping through the code the code exits the Set portion of the property and goes to the Get portion, it does that twice and then goes to the next Object so I can't figure out what is passing the null value.  The SelectedValue gets correct value when I open the program, but gets nulls when I switch tabs.

I am new to WPF so I am not sure what I am doing.

I know it's probably impossible to tell what is causing this without seeing the entire program, but maybe someone had similar issue and has an advice on how to trouble shoot this or at least some suggestion on how to create an UserControl.

Here's the XAML to my custom UserControl


<UserControl x:Class="Vtsr.Views.CustomControls.VisitDataField"
             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:customControls="clr-namespace:Vtsr.Views.CustomControls"
             mc:Ignorable="d"
             x:Name="VisitDataFieldControl"
             d:DesignHeight="21" d:DesignWidth="300">

    <UserControl.Resources>
        <Style TargetType="ComboBox" x:Key="ComboBoxStyle">
            <Setter Property="Height" Value="20"></Setter>
            <Setter Property="FontSize" Value="{Binding FontSize}"></Setter>
        </Style>

        <Style TargetType="ComboBoxItem" x:Key="ComboBoxItemStyle">
            <Setter Property="BorderBrush" Value="Gray"></Setter>
            <Setter Property="BorderThickness" Value="0.0"></Setter>
        </Style>

        <Style x:Key="TextBlockStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="{Binding FontSize}"></Setter>
            <Setter Property="FontWeight" Value="Bold"></Setter>
            <Setter Property="Margin" Value="3"></Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="TextDecorations" Value="Underline" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <Grid DataContext="{Binding ElementName=VisitDataFieldControl}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="100"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <TextBlock x:Uid="TxbLabel" x:Name="DataLabel" Margin="1,1,5,1" VerticalAlignment="Center" Width="{Binding LabelWidth}"
                           Text="{Binding DataLabelValue}" MinWidth="20" Grid.Row="0" Grid.Column="0" Style="{StaticResource TextBlockStyle}"></TextBlock>

        <customControls:FieldTextBox Text="{Binding DataField}" Grid.Row="0" Grid.Column="1" Margin="1,1,5,1" MouseRightButtonDown="TextBox_MouseRightButtonDown"></customControls:FieldTextBox>
        <ComboBox ItemsSource="{Binding UnitsList}" Grid.Row="0" Grid.Column="2" Style="{StaticResource ComboBoxStyle}" 
                                        ItemContainerStyle="{StaticResource ComboBoxItemStyle}" SelectedValue="{Binding SelectedUnit, Mode=TwoWay}">

        </ComboBox>
    </Grid>
</UserControl>

Here's code for the custom UserControl

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using Vtsr.Model;

namespace Vtsr.Views.CustomControls
{
    /// <summary>
    /// Interaction logic for VisitDataField.xaml
    /// </summary>
    public partial class VisitDataField : INotifyPropertyChanged
    {
        public VisitDataField()
        {
            InitializeComponent();
        }

        public void Connect(int connectionId, object target)
        {
            throw new NotImplementedException();
        }

        public static readonly DependencyProperty LabelWidthProperty = DependencyProperty.Register("LabelWidth", typeof(int), typeof(VisitDataField), null);
        public int LabelWidth
        {
            get
            {
                return (int)GetValue(LabelWidthProperty);
            }
            set
            {
                SetValue(LabelWidthProperty, value);
            }
        }

        public static readonly DependencyProperty DataFieldProperty = DependencyProperty.Register("DataField", typeof(string), typeof(VisitDataField), null);
        public string DataField
        {
            get { return (string)GetValue(DataFieldProperty); }
            set { SetValue(DataFieldProperty, value); }
        }

        public static readonly DependencyProperty SelectedUnitProperty = DependencyProperty.Register("SelectedUnit", typeof(string), typeof(VisitDataField), null);
        public string SelectedUnit
        {
            get
            {
                return (string)GetValue(SelectedUnitProperty);
            }
            set
            {
                SetValue(SelectedUnitProperty, value);
            }
        }
        public string DataLabelValue
        {
            get
            {
                return _dataLabelValue;
            }
            set
            {
                _dataLabelValue = value;
                if (CaptionDictinaryViewModel.CaptionDictionary != null)
                _dataLabelValue = CaptionDictinaryViewModel.CaptionDictionary.ContainsKey(value) ? CaptionDictinaryViewModel.CaptionDictionary[value] : value;

                OnPropertyChanged("DataLabelValue");
            }
        }

        private string _dataLabelValue = "Data Label";

        public static readonly DependencyProperty UnitsListProperty = DependencyProperty.Register("UnitsList", typeof(ObservableCollection<string>), typeof(VisitDataField), null);

        public ObservableCollection<string> UnitsList
        {
            get { return (ObservableCollection<string>) GetValue(UnitsListProperty); }
            set { SetValue(UnitsListProperty, value);}
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string name)
        {
            var handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        private void TextBox_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {

        }
    }
}


Peter

How to write to metadata.Location?

$
0
0
Hi everyone, I want to write a new location data into a picture by using Clone method of Bitmapmetadata. However, it is read only. So do you know which way I can do to write to the location of the image? Thanks in advance.

I Cant Use Dialog Boxes In My Project

$
0
0

Please See this Link And Help Me

http://social.msdn.microsoft.com/Forums/getfile/443032



Still problems with THIS forum not others

$
0
0

I am still having problems with this forum.  The filters will stay as Unanswered and there is nothing I can do to stop this.  Other forums work fine.

Perhaps if MS employees would stop moving my posts to a forum that no one goes to and FIX THIS I could stop trying to get it fixed.

Is there no one at MS that give a crap about this????


Lloyd Sheen

XBAP ApplicationAssertion

$
0
0

Hello,

My XBAP application is working in fine when accessed directly, however when I try to access it through  IBM Webseal Junction (single sign-on, after authentication forwards request to my webserver IIS 7 URL) the application fails with the below error. This is a full trust application and usually prompts for user permission before running. However when accessed using the Webseal junction, it fails.

Any recommendations / suggestions are much appreciated.

Error Log

=======

IDENTITIES

                Deployment Identity                      : index.xbap, Version=1.0.0.40, Culture=neutral, PublicKeyToken=e79df87169ddf13f, processorArchitecture=msil

                Application Identity                        : index.exe, Version=1.0.0.40, Culture=neutral, PublicKeyToken=e79df87169ddf13f, processorArchitecture=msil, type=win32

 

APPLICATION SUMMARY

                * Online only application.

                * Browser-hosted application.

 

ERROR SUMMARY

               Below is a summary of the errors, details of these errors are listed later in the log.

                * An exception occurred while downloading the application. Following failure messages were detected:

                                + The AssertApplicationRequirements method either did not get called or timed out. There is no trust decision before the commit.

 

Key Binding does not work always in MVVM application

$
0
0

 Hi,

I have a Usercontrol which is designed as an MVVM application and hosted in another WPF application(by other parties).

Usercontrol is composed of Left side and Right side usercontrols.

To add the shortcut behavior on the usercontrols,i have defined Key Binding on the Left and Right side controls.

Shortcut keys are defined for Ctrl+C,Ctrl+V,Ctrl+P,Delete,Page Up,Page Down,Home and End.

 <UserControl.InputBindings>
        <KeyBinding Key="A" Modifiers="Control" Command="{Binding Path= SelectAllCommand}"/>
        <KeyBinding Key="None" Modifiers="Control" Command="{Binding Path= DeselectAllCommand}"/>
        <KeyBinding Key="X" Modifiers="Control" Command="{Binding Path= CutCommand}"/>
        <KeyBinding Key="C" Modifiers="Control" Command="{Binding Path= CopyCommand}"/>
        <KeyBinding Key="V" Modifiers="Control" Command="{Binding Path= PasteCommand}"/>
        <KeyBinding Key="P" Modifiers="Control" Command="{Binding Path= PrintCommand}"/>
        <KeyBinding Key="Delete" Command="{Binding Path= DeleteCommand}"/>
        <KeyBinding Key="Home" Command="{Binding Path= DisplayPageCommand}" CommandParameter="1"/>
        <KeyBinding Key="End" Command="{Binding Path= DisplayPageCommand}" CommandParameter="{Binding Path=PageCount}"/>
        <KeyBinding Key="PageUp" Command="{Binding Path= ScrollUpdateCommand}" CommandParameter="{Binding Path=PageUpValue}"/>
        <KeyBinding Key="PageDown" Command="{Binding Path= ScrollUpdateCommand}" CommandParameter="{Binding Path=PageDownValue}"/>
        <KeyBinding Key="Up" Command="{Binding Path= ScrollUpdateCommand}" CommandParameter="{Binding Path=ArrowUpValue}"/>
        <KeyBinding Key="Down" Command="{Binding Path= ScrollUpdateCommand}" CommandParameter="{Binding Path=ArrowDownValue}"/>
    </UserControl.InputBindings>

Problem is that shortcut works initially and in between shortcuts stop working (probably due to  control losing focus).

How to make the shortcuts work ?

Please suggest.

Regards

Vinutha

 

 

 


VINUTHA

In WPF how to resize the columns with min width set in DataGrid width set to auto.

$
0
0

Hi,

My application is like, user can add columns as many as he wants to DataGrid at runtime. And datagrid should also have automatic width when user resizes the window.

For this I have a datagrid width set to 'Auto'.  And columns get added runtime by user. And all the columns width is not fixed. And every column has a min width set so that user cannot resize a column beyond this min width.  This is also part of my requirement. This is working fine.

Now my problem is when there are many columns user added, datagrid width is increased automatically with scroll bar that we provided. And datagrid width is setting automatically such that all the columns width reaches to min width. But in this case, user is not able to resize the columns as min width for all the columns is reached. At the time say for example few cells have more lengthy text, user will not be able to see the full text (because this text cannot fit into the min width provided for the column). But I am providing a tooltip and trimming the text with ellipse at end. But I still need to provide the resizing to the columns, how can I do this?

Thanks in advance.

Regards,

Mohan.

Viewing all 18858 articles
Browse latest View live


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