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

Regarding the shape of the colour displayed behind the arrow of the combobox

$
0
0

I would like for the shape to be a circle. How do I get this to be circular instead of a square colour?

MainWindow:

<Window x:Class="WPF_UI_Design_2.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"><Grid><GroupBox Header="Control Prototyping for DVLink" Background="White" Foreground="#00c7d5" ><StackPanel HorizontalAlignment="Center" Orientation="Vertical" VerticalAlignment="Top" Height="150" Width="180"><TextBox VerticalContentAlignment="Center"  SelectionBrush="#23b7c2" Margin="0,10,0,0" Text="12243-2343-34534" Template="{StaticResource TextBoxBaseControlTemplate}" Foreground="{DynamicResource DVLinkBlueBrush}" Height="25" Width="120"/><ComboBox Text="Edit me!"  IsEditable="True"><ComboBoxItem>20</ComboBoxItem><ComboBoxItem>40</ComboBoxItem><ComboBoxItem>60</ComboBoxItem></ComboBox><ComboBox Text="20" IsEditable="False"><ComboBoxItem>20</ComboBoxItem><ComboBoxItem>40</ComboBoxItem><ComboBoxItem>60</ComboBoxItem></ComboBox></StackPanel></GroupBox></Grid></Window>

App.xaml

<Application x:Class="WPF_UI_Design_2.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"><Application.Resources><!--Control colors.--><Color x:Key="InputBoxBorderColour">Black</Color><Color x:Key="DVLinkBlue">#FF00C7D5</Color><SolidColorBrush  x:Key="DVLinkBlueBrush" Color="{DynamicResource DVLinkBlue}" /><Color x:Key="DVLinkBlueGradientStop">White</Color><Color x:Key="DVLinkBorderGray">Gray</Color><SolidColorBrush  x:Key="DVLinkBorderGrayBrush" Color="{DynamicResource DVLinkBorderGray}" /><Color x:Key="WindowColor">#FFE8EDF9</Color><Color x:Key="ContentAreaColorLight">#FF6CD0E0</Color><Color x:Key="ContentAreaColorDark">#FF47A8B8</Color><Color x:Key="DisabledControlLightColor">#FF6CD0E0</Color><Color x:Key="DisabledControlDarkColor">#FF47A8B8</Color><Color x:Key="DisabledForegroundColor">#FF888888</Color><Color x:Key="SelectedBackgroundColor">#FF47A8B8</Color><Color x:Key="SelectedUnfocusedColor">#FFDDDDDD</Color><Color x:Key="ControlLightColor">White</Color><Color x:Key="ControlMediumColor">#FF47A8B8</Color><Color x:Key="ControlDarkColor">#FF34ABBF</Color><Color x:Key="ControlMouseOverColor">#FF34ABBF</Color><Color x:Key="ControlPressedColor">#FF6CD0E0</Color><Color x:Key="GlyphColor">#FF444444</Color><Color x:Key="GlyphMouseOver">sc#1, 0.004391443, 0.002428215, 0.242281124</Color><!--Border colors--><Color x:Key="BorderLightColor">#FFCCCCCC</Color><Color x:Key="BorderMediumColor">#FF888888</Color><Color x:Key="BorderDarkColor">#FF444444</Color><Color x:Key="PressedBorderLightColor">#FF888888</Color><Color x:Key="PressedBorderDarkColor">#FF444444</Color><Color x:Key="DisabledBorderLightColor">#FFAAAAAA</Color><Color x:Key="DisabledBorderDarkColor">#FF888888</Color><Color x:Key="DefaultBorderBrushDarkColor">Black</Color><!--Control-specific resources.--><Color x:Key="HeaderTopColor">#FFC5CBF9</Color><Color x:Key="DatagridCurrentCellBorderColor">Black</Color><Color x:Key="SliderTrackDarkColor">#FFC5CBF9</Color><Color x:Key="NavButtonFrameColor">#FF3843C4</Color><ControlTemplate x:Key="ComboBoxToggleButton"
                 TargetType="{x:Type ToggleButton}"><Grid><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition Width="20" /></Grid.ColumnDefinitions><Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="2" BorderThickness="1" ><Border.BorderBrush> <SolidColorBrush Color="{DynamicResource DVLinkBorderGray}" /><!--This will change the colour of the combobox's textbox border (not the dropdown's border)--></Border.BorderBrush><Border.Background><!--This controls the background displayed behind the combobox arrow that brings up the dropdown --><LinearGradientBrush StartPoint="0,0" EndPoint="0,1"><LinearGradientBrush.GradientStops><GradientStopCollection><GradientStop Color="{DynamicResource DVLinkBlueGradientStop}" /><GradientStop Color="{DynamicResource DVLinkBlue}" Offset="1.0" /></GradientStopCollection></LinearGradientBrush.GradientStops></LinearGradientBrush></Border.Background></Border><Border Grid.Column="0"
                        CornerRadius="2,0,0,2"
                        Margin="0.75"><!--Margin of 0.75 above neccessary to prevent the RHS colour from 'spilling' throug on the left --><Border.Background><SolidColorBrush Color="{DynamicResource ControlLightColor}"/></Border.Background></Border><!-- The following Path will draw the arrow to indicate that the control may be clicked for more options --><Path x:Name="Arrow"
                      Grid.Column="1"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Data="M 0 0 L 4 4 L 8 0 Z" ><Path.Fill><SolidColorBrush Color="{DynamicResource ControlMediumColor}"/></Path.Fill></Path></Grid></ControlTemplate><ControlTemplate x:Key="ComboBoxTextBox"
                 TargetType="{x:Type TextBox}"><Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}"/></ControlTemplate><Style x:Key="{x:Type ComboBox}"
               TargetType="{x:Type ComboBox}"><Setter Property="SnapsToDevicePixels" Value="true" />           <Setter Property="Margin" Value="0,10,0,0"/><Setter Property="Width" Value="120"/><Setter Property="Height" Value="30"/><Setter Property="OverridesDefaultStyle" Value="true" /><Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /><Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /><Setter Property="ScrollViewer.CanContentScroll" Value="true" /><Setter Property="MinWidth" Value="120" /><Setter Property="MinHeight" Value="30" /><Setter Property="VerticalContentAlignment" Value="Center"/><Setter Property="Foreground" Value="{DynamicResource DVLinkBlueBrush}"/> <!-- * The currently selected text : displayed in the textbox part of combobox *--><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ComboBox}"><Grid><VisualStateManager.VisualStateGroups><VisualStateGroup x:Name="CommonStates"><VisualState x:Name="Normal" /><VisualState x:Name="Disabled"><Storyboard><ColorAnimationUsingKeyFrames Storyboard.TargetName="PART_EditableTextBox"
                                                Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)"><EasingColorKeyFrame KeyTime="0"
                                         Value="{StaticResource DisabledForegroundColor}" /></ColorAnimationUsingKeyFrames></Storyboard></VisualState></VisualStateGroup><VisualStateGroup x:Name="EditStates"><VisualState x:Name="Editable"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                 Storyboard.TargetName="PART_EditableTextBox"><DiscreteObjectKeyFrame KeyTime="0"  Value="{x:Static Visibility.Visible}" /></ObjectAnimationUsingKeyFrames><ObjectAnimationUsingKeyFrames
                                                Storyboard.TargetProperty="(UIElement.Visibility)"
                                                 Storyboard.TargetName="ContentSite"><DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="{x:Static Visibility.Hidden}" /></ObjectAnimationUsingKeyFrames></Storyboard></VisualState><VisualState x:Name="Uneditable" /></VisualStateGroup><VisualStateGroup x:Name="FocusStates"><VisualState x:Name="Focused"/><!-- ripped out the FocusedState Storyboard so it doesnt do anything when focused.--><VisualState x:Name="Unfocused"/></VisualStateGroup></VisualStateManager.VisualStateGroups><ToggleButton x:Name="ToggleButton"
                                          Template="{StaticResource ComboBoxToggleButton}"
                                          Grid.Column="2"
                                          Focusable="false"
                                          ClickMode="Press"
                                          IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/><ContentPresenter x:Name="ContentSite"
                                              IsHitTestVisible="False"
                                              Content="{TemplateBinding SelectionBoxItem}"
                                              ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                              ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                              Margin="3,3,23,3"
                                              VerticalAlignment="Center" 
                                              HorizontalAlignment="Left"></ContentPresenter><TextBox x:Name="PART_EditableTextBox"
                                     Style="{x:Null}"     
                                     Template="{StaticResource ComboBoxTextBox}"
                                     HorizontalAlignment="Left"
                                     VerticalAlignment="Center"
                                     SelectionBrush="#23b7c2"
                                     VerticalContentAlignment="Center"
                                     Margin="3,3,23,3"
                                     Focusable="True" 
                                     Background="Transparent"
                                     Text="{TemplateBinding Text}"
                                     Visibility="Hidden"
                                     Foreground="{DynamicResource DVLinkBlueBrush}"
                                     IsReadOnly="{TemplateBinding IsReadOnly}"/><!-- ** VerticalAlignment centers the text in the editable part of the combobox ** --><Popup x:Name="Popup"
                                   Placement="Bottom"
                                   IsOpen="{TemplateBinding IsDropDownOpen}"
                                   AllowsTransparency="True"
                                   Focusable="False"
                                   PopupAnimation="Slide"><Grid x:Name="DropDown"
                                      SnapsToDevicePixels="True"
                                      MinWidth="{TemplateBinding ActualWidth}"
                                      MaxHeight="{TemplateBinding MaxDropDownHeight}"><Border x:Name="DropDownBorder"
                                            BorderThickness="1" ><Border.BorderBrush><SolidColorBrush Color="{DynamicResource BorderMediumColor}" /></Border.BorderBrush><Border.Background><SolidColorBrush Color="{DynamicResource ControlLightColor}" /></Border.Background></Border><ScrollViewer Margin="4,6,4,6"
                                                  SnapsToDevicePixels="True"><StackPanel IsItemsHost="True"
                                                    KeyboardNavigation.DirectionalNavigation="Contained" /></ScrollViewer></Grid></Popup></Grid><ControlTemplate.Triggers><Trigger Property="HasItems"
                                     Value="false"><Setter TargetName="DropDownBorder"
                                        Property="MinHeight"
                                        Value="95" /></Trigger><Trigger Property="IsGrouping"
                                     Value="true"><Setter Property="ScrollViewer.CanContentScroll"
                                        Value="false" /></Trigger><Trigger SourceName="Popup"
                                     Property="AllowsTransparency"
                                     Value="true"><Setter TargetName="DropDownBorder"
                                        Property="CornerRadius"
                                        Value="4" /><Setter TargetName="DropDownBorder"
                                        Property="Margin"
                                        Value="0,2,0,0" /></Trigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsEditable" Value="false" /><Condition Property="SelectedItem" Value="{x:Null}" /></MultiTrigger.Conditions><Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/></MultiTrigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style><Style x:Key="{x:Type ComboBoxItem}"
               TargetType="{x:Type ComboBoxItem}"><Setter Property="Foreground" Value="Black" /><!-- * text displayed in the dropdown is black in colour * --><Style.Resources><SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{DynamicResource DVLinkBlue}"/><!-- * when the mouse moves over a combobox entry (item), the colour is our own custom blue, instead of windows system default colour * --></Style.Resources></Style><ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}"><Border Background="{TemplateBinding Background}" BorderBrush="{DynamicResource DVLinkBorderGrayBrush}"
                BorderThickness="1" CornerRadius="2"><ScrollViewer x:Name="PART_ContentHost"/> <!-- This line will ensure that the text is displayed --></Border></ControlTemplate></Application.Resources></Application>

Regards,

Harriet


Hide Expander Header and move expander content to top wpf

$
0
0

Pls see image below.

Im hiding the header hereby setting the visibility to collapsed. But I wanted to have the content show beside the expander button.

Binding Lost Focus on ListView in purely mvvm based application.

$
0
0

I have a ListView (having GridView and two columns to display data) bound to an observable collection.

Observable collection has KeyValuePair of Int,Bool. This bool Value is shown as a Checkbox in the ListView.   I tried attaching 'EventTrigger' based on 'LostFocus' command binding to the ListView , BUT it is not firing. Instead the command fires when i check/uncheck items inside the ListView (which is not required).  

Is there any way I can bind LostFocus command binding ,  as soon as i click out of the ListView (for a purely mvvm based application) 

Thanks.

How to display hierarchical data(tree) in DataGrid of WPF?

$
0
0

Hi All,

Is there a way to display hierarchical data(TreeView) in DataGrid(WPFToolKit) as the following:

Thanks,

How to remove the system from dropping shadows on controls

$
0
0

Hello All,

Yet another question when you define your controls with templates and styles - Windows seems to create its own shadow around controls, even though I have not put those in. In the control template or style, I cannot find any dropshadow elements.

here is a pic: 

When you look at the pic, please zoom it up to a high factor, such as 800%. Around the borders, (and even with the text) you can see there is some shadow going around. I would like to get rid of this shadow. Any ideas would be most welcomed.

Regards,

Harriet

How to make XAML vector graphic a static resource of the class in the code behind ?

$
0
0

I was playing with a user control that requires just a few vector images but a large number of them on the face of the control and several controls will be used in the window. The graphics was created as XAML vector and I would like to keep it that way. However if I put the graphics of the images into the XAML <Resources> of the user control they seem to belong to the instance of the control. In the code behind I wanted to have:

private static ImageSource myImages[];

And then I wanted to create the array and preload the images from XAML using static constructor of the class. The idea here is that I only have few images but multiple instances of the same user control. I don't want to keep recreating those images from resources every time the new control is created. However I have no idea how to access images stored in XAML in resources section of the user control from the static constructor. The class does not have "FindResource" function. Only it's instance. I'm not even sure if putting XAML code into <Resources> section of the user control can be interpreted as a static class data. Sure, I could put images into the App resources but this does not seem clean self containing user control and it is not what I want. I want the control to contain all it's data so I can reuse it in many other projects years later by simply plugging only the control files without much reverse engineering into what I have done months ago.

Any ideas ?

Programmatically select row from DataGrid where ID in Column ID is ... VB.net

$
0
0

Hi all,

Is it possible to programmatically select row from DataGird where Column ID = ID (from textbox  txtIMID.text on UserControl) on UserControl load?

Thank you in advance


Mathh

wpf bitmap image

$
0
0
Hello everyone, 
I have a WPF program in which I'm showing 128 images, and for each, I need to a) play an audio file and b) have an arrow point to a certain part of the picture. Because each pictures scale and size is different, the arrow pointer needs to be customized to each picture. That's 512 pictures I need to add arrows to. If I do that I can simply change the picture in the space of showing each with the arrow burned into the picture. 

My question is...is there any other / easier way to do this? Editing 512 pictures to include arrows in them is not my idea of a good time. Am I thinking about this wrong? 
Thanks, Dave

Custemization of datagrid

$
0
0

I've a datagrid in my wpf application. I've added item to it. but when i run , it show extra row at the bottom . how can i remove it? now my second question is that , my datagrid is looks very simple ,i want to customize it like this .
i want my datagrid looks like this.

but my datagrid looks like this 

my datagrid

<DataGrid Name="dGrid" HorizontalAlignment="Left"
                  VerticalAlignment="Top" AutoGenerateColumns="True" ></DataGrid>

this is how , i bind data to my datagrid

public MainWindow()
        {
            InitializeComponent();
            Bind();
        }
        public void Bind()
        {
            SqlConnection con = new SqlConnection("database=Assignment;server=.;integrated security=true");
            SqlCommand cmd = new SqlCommand("select * from Students", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dGrid.ItemsSource = ds.Tables[0].DefaultView;
        }

Change Grid.RowDefinitions in Grid.ColumnDefinitions by code

$
0
0

Hello

I developed a news system in  WPF / C #. 
My default Grid is separated into two Grid, TOP side displays the titles and details are displayed in the BOTTOM side. 

TO DO
Allow the user to change the view, for example, onclick on the button Style 2, I want my Grid display changes, 
that my Grid is separated now into 2 columns, LEFT for titles  and Right for details. 
therefore it will be 

Style1 click Horizontal display 
Style2 click Vertical display 
I would like to keep in both case GridSplitter  between columns or rows. 

This is what I have done. 
First I used a StackPanel in which I displayed my 2 block. 

<StackPanel Name="bloc" Orientation="Vertical" ><Grid Name="blocOne" Background="#FFA28282" ></Grid><Grid Name="blocTwo"  Background="#FF726161" ></Grid></StackPanel>

Onclick I used this code,

private void Style2_Click(object sender, RoutedEventArgs e)
 {
bloc.Orientation=System.Windows.Controls.Orientation.Horizontal;
}

private void Style1_Click(object sender, RoutedEventArgs e)
 {
bloc.Orientation=System.Windows.Controls.Orientation.Vertical;
            
}

it seems to work but if i insert  GridSlipter, it  does not work. 
Is there a way to use the GridSlipter without using Grid.RowDefinitions and Grid.ColumnDefinitions ? 

or if I use the following code. 

<Grid><Grid.RowDefinitions><RowDefinition Height="400" /><RowDefinition Height="5" /><RowDefinition Height="*" /></Grid.RowDefinitions><Grid Name="blocOne" Background="#FFA28282" ></Grid><GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" /><Grid Name="blocTwo" Grid.Row="2" Background="#FF726161" ></Grid></Grid>

how to change the rows to columns or columns to rows onclick?

or change Grid.RowDefinitions in Grid.ColumnDefinitions?

Like that i am sure to have my two styles with GridSlipter .

Thanks in advance


Custom component templated on top of ListView crashes the application

$
0
0

Hi,

Here i have memory leak issue with a custom component developed on top of ListView with templating. Below is the diagramatic representation of component and the way it is linked to its data context.

Problem: with a 1 second update of data this component leads application to crash within about 45 min - 1 hrs time in a machine with Quad core & 6 GB of RAM.



Below is the Xaml part of the component with template and style.

<Style TargetType="{x:Type local:Table}"><Setter Property="Template"><Setter.Value><ControlTemplate  x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:Table}, ResourceId=Table}"
                         TargetType="{x:Type local:Table}"><ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True"  HorizontalAlignment="Stretch" 
                                      VerticalAlignment="Stretch" ><Grid><ItemsControl x:Name="lstControlTable"   
                                          ItemsSource="{Binding}"                                         
                                          HorizontalAlignment="Stretch"
                                          Background="{TemplateBinding Background}" 
                                          Foreground="{TemplateBinding Foreground}" 
                                          VerticalAlignment="Stretch" 
                                          ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
                                          ScrollViewer.CanContentScroll="True" VirtualizingStackPanel.IsVirtualizing="True"><ItemsControl.ItemTemplate><DataTemplate><Grid><Grid.ColumnDefinitions>                                                   <ColumnDefinition Width="*"></ColumnDefinition></Grid.ColumnDefinitions>                                               <ItemsControl Grid.Column="0" Name="icSourceData" ItemsSource="{Binding Path=ChildData}" ItemTemplateSelector="{StaticResource TemplateSelect}" Height="Auto"><ItemsControl.Resources><!-- Matrix --><DataTemplate x:Key="Matrix"><!--<Expander VerticalAlignment="Top">--><ItemsControl Name="icMatrix" ItemsSource="{Binding}"><ItemsControl.ItemsPanel><ItemsPanelTemplate><UniformGrid Name="ugHorizontalColumns" Columns="{Binding ColumnCount}" Rows="{Binding RowCount}"
                                                                                     Margin="5,5,5,5"></UniformGrid></ItemsPanelTemplate></ItemsControl.ItemsPanel><ItemsControl.ItemTemplate><DataTemplate><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition/><RowDefinition/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="7*"></ColumnDefinition><ColumnDefinition Width="3*" ></ColumnDefinition></Grid.ColumnDefinitions><TextBlock Grid.Row="0" Grid.Column="0"  Text="{Binding HeaderName}" FontWeight="Bold" Foreground="DarkBlue" Background="{Binding Background}"
                                                                                       Style="{StaticResource HeaderStyle}" Margin="5,5,5,5"/><Button Grid.Column="1" Name="btnScalarUpdate" Content="Update" Tag="{Binding HeaderName}" Command="{x:Static local:Table.UpdateClick}" Width="Auto" Visibility="{Binding IsUpdateVisible}"></Button><ItemsControl Grid.Row="2" Grid.ColumnSpan="2"  Name="icMatrixContainer" ItemsSource="{Binding}" BorderBrush="DarkBlue" BorderThickness="1" 
                                                                                              ToolTip="{Binding Tip}" ><ItemsControl.ItemsPanel><ItemsPanelTemplate><UniformGrid Name="ugMatrixGrid" Columns="{Binding Columns}" Rows="{Binding Rows}"
                                                                                             Background="{Binding Background}" Margin="5,5,5,5"></UniformGrid></ItemsPanelTemplate></ItemsControl.ItemsPanel><ItemsControl.ItemTemplate><DataTemplate><Border  BorderBrush="{Binding Border}" BorderThickness="1"><TextBlock Grid.Column="1" Text="{Binding MatrixItem}" TextAlignment="{Binding Alignment}" Foreground="{Binding Foreground}"></TextBlock></Border></DataTemplate></ItemsControl.ItemTemplate></ItemsControl></Grid></DataTemplate></ItemsControl.ItemTemplate></ItemsControl><!--</Expander>--></DataTemplate></ItemsControl.Resources><ItemsControl.ItemsPanel><ItemsPanelTemplate><StackPanel Name="ugColumns" Margin="5,5,5,5" Height="Auto" FlowDirection="LeftToRight"  Orientation="Horizontal"/></ItemsPanelTemplate></ItemsControl.ItemsPanel></ItemsControl></Grid></DataTemplate></ItemsControl.ItemTemplate></ItemsControl><Rectangle x:Name="rectBorder" Stroke="{Binding Path=BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"/><!--</StackPanel>--></Grid><!--</ScrollBar>--></ScrollViewer></ControlTemplate></Setter.Value></Setter></Style>

What is wrong in the template? Is there a better way to do?




Apply Style/Trigger on Data Template

$
0
0

Hi,

I am working on Data Template in WPF where sample datatemplate:

<DataTemplate

<Border x:Name="MainBorder">

<TextBlock Text="SampleText" />

<ToggleButton x:Name="Toggle">

</ToggleButton>

</Border>

</DataTemplate>

Now, I have to apply trigger on toggle button where it should set border brush and border thickness on border.

Please help on approach.

comment / uncomment menu button in VS2012

$
0
0

Hi All.

I just install VS2012 and I didn't see comment/uncomment button in menu bar. Is it possible to install them in menu bar?

Thanks.

wpf application do not show messagebox, when not run as a admin user

$
0
0

Hi,

i face the issue related system user.

Explaination

- when i run application under admin rights, working fine, but i run application under normal user(not admin), application does not show messagebox.

this is not normal behavior.

please suggest any solution.

Thanks,

Rajnikant

Dynamic naming for objects

$
0
0

Hi

I want to create a object name based on the value from For loop. See the below example 

for (var i = 0; i < columnCount;i++ )
            {
                for (var j = 0; j < rowCount; j++)
                {                  
                    RadDiagramShapestring+ ij = new RadDiagramShape(); // external storage
                    {
                       
                    }
                }
            }

I want to give the name of RadDiagramShape as String+i+j.

For example if the values of i and j are 1,1 then the name should be string11.

Please help me how can we implement this kind of situation in C#.

Thanks

Karthik


Rendering Geometry Data in WPF

$
0
0

I have geometry data in sql table as following

POLYGON ((1071894.891487217 1253898.9852902349, 1072444.891487217 1253898.9852902349, 1072444.891487217 1254038.9852902349, 1071894.891487217 1254038.9852902349, 1071894.891487217 1253898.9852902349))

What is bestway to render the shapes in wpf with zooming facility

Very very urgent

Static dependency properties

$
0
0

Hi,

I have created a user control containing a combobox and other controls.

I have exposed a dependency property known as 'ItemSource' from user control i.e. bound to the ItemSource property of Combobox.

I used this user control twice in my xaml with two different collections bound to each user control respectively.

But due to static contexts one of my collection is getting overwritten by the other.Therefore both the controls get same collections.

 Please suggest me how to overcome this problem.

Thanks in advance.

Usercontrol dependency property binding issue

$
0
0

in my project i wanted to have a split window , so one side of the window will always load set of usercontrols which has basically datagrid. the usercontrol is selected based on the current view model. its work fine. But when the user select an item from the dataview i would like to open another usercontrol in the other side of the window, which consist of lot of textboxes and combo boxes. The problem starts here am not able to bind any value to this usercontrol. i could see that the property is getting value but every fields remains empty.

window.xaml

<Window.resources>

       DataTemplate DataType="{x:Type vm:ViewModel1}" >
              <loc:UserControl1  Items="{Binding Items}"  />
             </DataTemplate>
        <DataTemplate DataType="{x:Type vm:ViewModel2}">
            <loc:UserControl2/>
        </DataTemplate>
        <DataTemplate DataType="{x:Type vm:ViewModel3}">
            <loc:UserContro3l/>
        </DataTemplate>
 </Window.resources>

.

.

<ContentControl Content={Binding CurrentView}/> // works fine

<Grid>

<Grid.Resources>

<DataTemplate DataType="{x:Type vm:ViewModel1}">      // All usercontrols displays But Data is not binding
                        <loc:UC1 BName="{Binding Path=BName}"/>// BName is not binding
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type vm:ViewModel2}">
                        <loc:UC2/>
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type ViewModel3}">
                        <loc:UC3/>
                    </DataTemplate>
   </Grid.Resources>

</Grid>

In the usercontrols i have created dependeny properties and in the view model properties to bind them.

It will be great someone could tell me what am i doing wrong

How to get handle of an control in WPF???

$
0
0

Hi Guys

I am trying to get the handle of a canvas control using following piece of code :-

HwndSource source = (HwndSource)HwndSource.FromVisual(videoCanvas);
IntPtr hWnd = source.Handle;

but its giving same handle for canvas as well as the window.

Any other way to do it??????

Cross threading error on drawing to WPF from DataReceived event of SerialPort

$
0
0

I have a WPF/.Net 4.5.1 app which receives GPS coordinates from the serial port, and plots the coordinates on a map using the WPF GMap.Net control (http://greatmaps.codeplex.com/).

To plot the coordinates on the GMap control, one has to create a GMapMarker object, which gets added to the GMap control's GMapMarker collection. The GMapMarker object has a shape attribute, which is of type UIElement. One has to set this"shape" attribute to the Bitmap one wants to plot on the map. According to the examples on the author's website, I can do something like this:

public void AddMarker(double latitude, double longitude, System.Windows.Media.Imaging.BitmapImage bitmapImage)
{
        GMap.Net.PointLatLng point = new GMap.Net.PointLatLng(latitude, longitude);
        GMap.Net.GMapMarker marker = new GMap.Net.GMapMarker(point);
        System.Windows.Controls.Image image = new System.Windows.Controls.Image();
        image.Source = bitmapImage;
        marker.Shape = image;
        Map.Markers.Add(marker); 
}

This works perfectly if I call the function directly from, let's say, the Click even of a button placed on the window. But my problem is that I am calling this function from the DataReceived event of the .Net's serial port control. This gets fired whenever data arrived at the computer's serial port. So:  

System.IO.Ports.SerialPort _serialPort = new System.IO.Ports.SerialPort(); public void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { string data = serialPort1.ReadExisting(); double latitude, longitude; DecodeData(data, ref latitude, ref longitude);
System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
        bitmapImage.BeginInit();
        bitmapImage.UriSource = new Uri(@"C:\plot.png");
        bitmapImage.EndInit(); AddMarker(latitude, longitude, bitmapImage); }


When I call AddMarker() in this scenario, I get an error on the line:
        System.Windows.Controls.Image image = new System.Windows.Controls.Image();
The error is:
        "The calling thread must be STA, because many UI components require this."

So I did the following:

public void AddMarker(double latitude, double longitude, System.Windows.Media.Imaging.BitmapImage bitmapImage)
{
this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
        {
        GMap.Net.PointLatLng point = new GMap.Net.PointLatLng(latitude, longitude);
        GMap.Net.GMapMarker marker = new GMap.Net.GMapMarker(point);
        System.Windows.Controls.Image image = new System.Windows.Controls.Image();
        image.Source = bitmapImage;
        marker.Shape = image;
        Map.Markers.Add(marker); 
}));
}

Now I don't get an error on that line anymore, but I get an error on the next line:
        Image.Source = bitmapImage;
The error is:
        "The calling thread cannot access this object because a different thread owns it."

I've tried a million and one things, but I can't seem to come right. Any ideas anyone? Thanks.....


Fabricio Rodriguez - Pretoria, South Africa

Viewing all 18858 articles
Browse latest View live


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