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

[WPF] DatePicker and StringFormat

$
0
0

Hi,

in my grid I'm using a DatePicker (for show and edit).

When I edit the cells with Datepicker the format of date is "MM/dd/yyyy", how can I convert it in "dd/MM/yyyy"?

Why?

<DataGridTemplateColumn Header="{StaticResource datagridDatetime}"><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlock Text="{Binding DateTime, Mode=OneWay, StringFormat='dd/MM/yyyy'}"></TextBlock></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.CellEditingTemplate><DataTemplate><DatePicker SelectedDate="{Binding DateTime, StringFormat='dd/MM/yyyy'}"   /></DataTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>

Thanks.


WPF: How to make the first column does not show row separator and Left column separator in DataGrid?

$
0
0

Our WPF application uses DataGrid.

One of request is that first column of DataGrid does not show row separator and also does not show Left column separator. So it looks like the first column does not belong to the DataGrid. However, when select a row, the cell of first column still get selected.

How do we make it? Thx!


JaneC


WPF: How to make the Column and Row separator more wide and different color in datagrid?

$
0
0

Our application uses WPF.

One of request is make the DataGrid column separator and row separator more wide and use different color and remove original black separator of rows and columns.

Which template we need to modify to make it? Thx!


JaneC


Google material design

best way to create pages

$
0
0

Hi,

i have an application that contain several usercontrols that represent pages wich the user can navigate between .

what i want is to create all these pages at application start ,while showing  a splash screen for example .

and the application would be responsive , so i have to load all the pages in async  way.

so i am looking for some guidance on the best way to do that, small snippets could help too ;)

thanks and good day


WPF: How to make the SelectAll button unselect all when click the button second time?

$
0
0

Our application use WPF DataGrid.

We notice that click SelectAll button first time, it will select all cells in the grid.

click the second time does not do anything.

We have define the DataGrid style as following:

<Style x:Key="DataGridStyle1" TargetType="{x:Type DataGrid}"><Setter Property="Background" Value="Transparent" /><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" /><Setter Property="BorderBrush" Value="White" /><Setter Property="BorderThickness" Value="0,1,0,1" /><Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected" /><Setter Property="ScrollViewer.CanContentScroll" Value="true" /><Setter Property="ScrollViewer.PanningMode" Value="Both" /><Setter Property="Stylus.IsFlicksEnabled" Value="False" /><Setter Property="HorizontalGridLinesBrush" Value="{x:Null}"/><Setter Property="VerticalGridLinesBrush" Value="{x:Null}"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type DataGrid}"><Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}"
                                SnapsToDevicePixels="True"><ScrollViewer x:Name="DG_ScrollViewer" Focusable="false"><ScrollViewer.Template><ControlTemplate TargetType="{x:Type ScrollViewer}"><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="Auto" /><ColumnDefinition Width="*" /><ColumnDefinition Width="Auto" /></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="*" /><RowDefinition Height="Auto" /></Grid.RowDefinitions><Button Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
                                                    Command="{x:Static DataGrid.SelectAllCommand}"
                                                    Focusable="false"
                                                    Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}"
                                                    Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" /><DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter"
                                                                            Grid.Column="1"
                                                                            Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" /><ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                                                    Grid.Row="1"
                                                                    Grid.Column="0"
                                                                    Grid.ColumnSpan="2"
                                                                    CanContentScroll="{TemplateBinding CanContentScroll}" /><ScrollBar x:Name="PART_VerticalScrollBar"
                                                       Grid.Row="0"
                                                       Grid.RowSpan="3"
                                                       Grid.Column="2"
                                                       Margin="0,4"
                                                       Maximum="{TemplateBinding ScrollableHeight}"
                                                       Orientation="Vertical"
                                                       ViewportSize="{TemplateBinding ViewportHeight}"
                                                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                                       Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" /><Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"><Grid.ColumnDefinitions><ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" /><ColumnDefinition Width="*" /></Grid.ColumnDefinitions><ScrollBar x:Name="PART_HorizontalScrollBar"
                                                           Grid.Column="1" Grid.ColumnSpan="1"
                                                           Maximum="{TemplateBinding ScrollableWidth}"
                                                           Orientation="Horizontal"
                                                           ViewportSize="{TemplateBinding ViewportWidth}"
                                                           Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                                                           Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" /></Grid></Grid></ControlTemplate></ScrollViewer.Template><ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /></ScrollViewer></Border></ControlTemplate></Setter.Value></Setter><Style.Triggers><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsGrouping" Value="true" /><Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false" /></MultiTrigger.Conditions><Setter Property="ScrollViewer.CanContentScroll" Value="false" /></MultiTrigger></Style.Triggers></Style>

How can we change the behavior of SelectAll button, so click the second time, it will unselect All.

thx!


JaneC

PRISM questions:

$
0
0

Hi,

I've following questions on Prism:

1. Navigating from one Region to another Region?

2. Views are portion of UI. Then how and where views are combined to show in UI?

Kindly waiting for response.

Thanks,

Santosh

rendering custom adorner after zooming

$
0
0

I've developed a custom adorner that adorns a Canvas control.  The canvas contains a custom object (actually a line segment).  The adorner is simply a circle 10 pixels in diameter that is placed on top of the line segment.  The adorner's OnRender function draws this circle using the capabilities provided by the DrawingContext parameter.  When the canvas is zoomed, I make the following calculation at the beginning of OnRender:

ScaleTransform scaleTransform = new ScaleTransform();

scaleTransform.ScaleX = 1.0 / ZoomScaleFactor;

scaleTransform.ScaleY = 1.0 / ZoomScaleFactor;

drawingContext.PushTransform(scaleTransform);

... draw the circle then

drawingContext.Pop();

where ZoomScaleFactor is the new zoom scale factor for the canvas.  Due to the transform, the circle adorner remains the same size in spite of the zoom.  This is the desired result.  My problem is that the circle no longer lies on the line segment.  That is, the zoom operation has changed the position of the line segment but not the circle.  How can I maintain circle position relative to the line segment?

Thanks

dmm

 

          

 

System.NullReferenceException

$
0
0

I create a userControl which override the touchUp event. Based on solution, I add 

Window win = Window.GetWindow(this); win.TouchUp += (send, ee) => { MyTouchUpHandler(send, ee); };

Into the my user control in order to react for whole screen event. But after I add this in my xaml file, cannot load the designer, and error message 

System.NullReferenceException
Object reference not set to an instance of an object.
   at serverControl.UserControl1.UserControl1_Loaded(Object sender, RoutedEventArgs e) in C:\Users\zhehuang\OneDrive for Business 2\2015Thiese File\serverControl_v7\serverControl\UserControl1.xaml.cs:line 88
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   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)

The line 88 is 

            win.TouchUp += (send, ee) =>
            {
                MyTouchUpHandler(send, ee);
            };

I don't know anywhere is problem.

[WPF] How get the text in TextBlock

$
0
0

Hi,

I have a column in my grid:

<DataGridTemplateColumn Header="{StaticResource datagridScheduled}"><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlock Name="dgScheduleType" Text="{Binding Type, Mode=TwoWay}" /></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>

I use a <MultiBinding.Bindings> for a Converter, so, how can I pass the text in textblock to convert?

Thanks.

Month view, week view and working week view in outlook calendar in wpf

Making part of a string bold

$
0
0

I'm bring a title in to my WPF application from the settings file...

EG "name1 name"

Being a title, this value is used in many places but in some instances I'd like the first part to be in bold if possible.

Is there any way to do this 'before' I move it to a text block? Obviously with HTML I could place <b></b> around the first part.

Thanks

WPF datagrid EF DATABASE UPDATE

$
0
0

hello someone help

am getting null exception on foreign table value with navigation property already assigned. trying to update in datagrid,

       var ctx = new SomeEntities1();        TblStudentMission smm = new TblStudentMission();         TblStudentMission sm = e.Row.DataContext as TblStudentMission;
       

  staffMission.Remark = sm.Remark;                    smm.End_Mission = sm.End_Mission;                    smm.EOD_Mission = sm.EOD_Mission;                    smm.StaffId = sm.StudentId; //???null as sm.staffid is null                    smm.TblMission.Mission_Name = sm.TblMission.Mission_Name; // ???null as tblmissionis null                    sel.ctx1.TblStudentMission.Add(smm);

tblstudentmission has missionidok as foreign key


Beautiful Distractions...

SEAMLESS animation when scrollbar appear or disappear

$
0
0

Hello

 I have the following code in my WPF application.

<ScrollViewer x:Name="PG_ScrollViewer"  PreviewMouseWheel="Border_PreviewMouseWheel" ScrollChanged="PG_ScrollViewer_ScrollChanged"   ><ScrollViewer.Style><Style TargetType="{x:Type ScrollViewer}"><Style.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="VerticalScrollBarVisibility" Value="Auto"/><Setter Property="HorizontalScrollBarVisibility" Value="Disabled" /></Trigger><Trigger Property="IsMouseOver" Value="False"><Setter Property="VerticalScrollBarVisibility" Value="Hidden"/><Setter Property="HorizontalScrollBarVisibility" Value="Disabled" /></Trigger></Style.Triggers></Style></ScrollViewer.Style><Border x:Name="Border" Background="#585858"  Margin="0"
                                    BorderThickness="0"    ><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="*" /><ColumnDefinition  Width="314"/></Grid.ColumnDefinitions><TextBlock   Text="{DynamicResource Description}" Grid.Column="0"     Margin="10,15,0,0" TextWrapping="WrapWithOverflow"    FontWeight="Normal" VerticalAlignment="Top" Padding="0,0,10,0" FontSize="15" FontFamily="Segoe UI Light" TextAlignment="Justify"    /></Grid><Border Grid.Column="1" BorderBrush="#ededed" BorderThickness="1" Width="180" Height="180" Margin="10,10,10,10" VerticalAlignment="Top"><Image Source="{DynamicResource Logo}" Grid.Column="0"  Margin="5" HorizontalAlignment="Left"   Width="170" VerticalAlignment="Top"></Image></Border></Border></ScrollViewer>

When ISMOUSEOVER is False, the contents of my TextBlock, changes suddenly or abruptly.

How to make it SEAMLESS ??

Best migration path from MFC/C++ to c#/.NET ?

$
0
0

I have a Visual Studio 2010 C++/MFC application that I would like to upgrade to Visual Studio 2013 C++/C#/.NET (basically eliminate the MFC portion of it). The MFC application is document/view-based. 

Can anyone tell me the best and most efficient way to do this? Are there any tools to help with this? I would appreciate any guidance that would make this as painless and bug-free as possible. 


Binding problem with CurrentItem (IsSynchronizedWithCurrentItem)

$
0
0

Hello together,

I use the following code :

    <Grid>
        <ListView IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding CollectionMember}" SelectionMode="Single" HorizontalAlignment="Left" Height="143" Margin="23,21,0,0" VerticalAlignment="Top" Width="309">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="120"/>
                    <GridViewColumn Header="Code" DisplayMemberBinding="{Binding CodeCountry}" Width="60"/>
                </GridView>
            </ListView.View>
        </ListView>
        <TextBox Text="{Binding CollectionMember.CurrentItem.Name}" HorizontalAlignment="Left" Height="23" Margin="23,187,0,0" VerticalAlignment="Top" Width="309"/>
        <ComboBox SelectedValue="{Binding CollectionMember.CurrentItem.CodeCountry}" SelectedValuePath="Code" ItemsSource="{Binding ListCountry}" HorizontalAlignment="Left" Margin="23,231,0,0" VerticalAlignment="Top" Width="309">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </Grid>

public partial class MainWindow : Window
{
    private DC dc = null;

    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        dc = new DC();

        dc.CollectionMember.Add(new Member { Name = "Steve", CodeCountry = "US" });
        dc.CollectionMember.Add(new Member { Name = "Piere", CodeCountry = "FR" });
        dc.CollectionMember.Add(new Member { Name = "Hans", CodeCountry = "DE" });
        dc.CollectionMember.Add(new Member { Name = "Rocco", CodeCountry = "IT" });

        dc.ListCountry.Add(new Country { Code = "US", Name = "USA" });
        dc.ListCountry.Add(new Country { Code = "FR", Name = "France" });
        dc.ListCountry.Add(new Country { Code = "DE", Name = "Deutschland" });
        dc.ListCountry.Add(new Country { Code = "IT", Name = "Italia" });

        DataContext = dc;
    }
}

public class Member
{
    public string Name { get; set; }
    public string CodeCountry { get; set; }
}

public class Country
{
    public string Code { get; set; }
    public string Name { get; set; }
}

public class DC
{
    private ObservableCollection<Member> _CollectionMember = new ObservableCollection<Member>();
    public ObservableCollection<Member> CollectionMember
    {
        get { return _CollectionMember; }
        set { _CollectionMember = value; }
    }

    private List<Country> _ListCountry = new List<Country>();
    public List<Country> ListCountry
    {
        get { return _ListCountry; }
        set { _ListCountry = value; }
    }
}

Code Download via:

http://www.file-upload.net/download-10343926/CurrentItem.zip.html

If I change the TextBox the Collection will be synchronized, but not so with the ComboBox.
Why does the TextBox working but not the ComboBox?

Thanks you for your help.
Regards
Torsten

How would I make it so that when "deleting" an image I can make it so that the delete key does it or a button I put on the application?

$
0
0

How would I make it so that when "deleting" an image I can make it so that the delete key does it or a button I put on the application?

I want it so that I can use either a button on the designer window or the delete key. I know how to do the or part but the trouble I'm having is coding the button in.

if (LastImageClicked != null && (e.Key == Key.Delete || Button))

This is the code that I have in the format I'm looking for I just don't know how to do it. Thanks for your help!

TextBlock display Animation

$
0
0

Hello 

I have the following code in my WPF application.

ToggleButton Control

<ToggleButton x:Name="rMore" Height="22"   VerticalAlignment="Bottom" Width="145" FontSize="13"  HorizontalAlignment="Left" Margin="34,0,0,15"><ToggleButton.Template><ControlTemplate ><Border  Margin="0,0,0,0" Name="box" CornerRadius="7" Background="{x:Null}" BorderBrush="#d3d3d3" BorderThickness="0" Padding="2"><ContentPresenter x:Name="cp"    VerticalAlignment="Top"  HorizontalAlignment="Center"  /></Border><ControlTemplate.Triggers><DataTrigger Binding="{Binding IsChecked, ElementName=rMore}" Value="false"><Setter TargetName="cp"   Property="Content"  Value="View More Description" /><Setter TargetName="box"   Property="Background"  Value="#000" /></DataTrigger><DataTrigger Binding="{Binding IsChecked, ElementName=rMore}" Value="true"><Setter TargetName="cp"   Property="Content"  Value="View Less Description" /><Setter TargetName="box"   Property="Background"  Value="#333333" /></DataTrigger><Trigger Property="IsMouseOver" Value="false"><Setter    Property="Foreground"  Value="#fff" /></Trigger><Trigger Property="IsMouseOver" Value="true"><Setter    Property="Foreground"  Value="#fff" /><Setter TargetName="box"   Property="Background"  Value="#00ad78" /></Trigger></ControlTemplate.Triggers></ControlTemplate></ToggleButton.Template></ToggleButton>

is this control is checked , i display the content of My Textblock

TextBlock Control

<TextBlock x:Name="SeeContent"     Text="{DynamicResource Description}"   Margin="10,0,0,0" TextWrapping="WrapWithOverflow"   HorizontalAlignment="Left" FontWeight="Normal" Padding="0,0,10,0" FontSize="15" FontFamily="Segoe UI Light" TextAlignment="Justify"    ><TextBlock.Style><Style TargetType="{x:Type TextBlock}"><Style.Triggers><DataTrigger Binding="{Binding IsChecked, ElementName=rMore}" Value="false"><Setter Property="Visibility" Value="Collapsed"/></DataTrigger><DataTrigger Binding="{Binding IsChecked, ElementName=rMore}" Value="true"><Setter Property="Visibility" Value="Visible" /></DataTrigger></Style.Triggers></Style></TextBlock.Style></TextBlock>

How can i add animation (slide Up and slide Down )  on Toggle Button Checked and unchecked ???

Thanks

How to avoid Textboxes growing on typing?

$
0
0
Hi,

I have a very simple and basic question, yet were unable to find it being discussed anywere. With the standard WPF Textbox control, when you don't set it's Witdth property, the text will autosize. That's ok, but the text will also grow when you type in a text longer that the view area.

This behaviour is however annoying. I want the textbox to use the width it is given by the parent panel (grid, stackpanel), but not to dictate the width back. The only way one can stop the growth seems to be setting the Width or MaxWidth property, but that is pretty poor windows.forms solution. When I have a window containing a grid and there a couple of textboxes, then I want to resize the textboxes to resize when user resizes the window. But withouth the textboxes growing wild when user types.

I tried binding MaxWidth to ActualWidth, which was not a good idea (the textbox remained at zero width), I tried playing with MeasureOverride and ArrangeOverride, none of them turned to work as expected. At best I was able to make the textbox stop growing, but still the caret was diappearing beyond the right edge like the textbox still continued there.

So, is there any standard way to stop the textbox growing as the user types?

WPF: Why forward and backward continue selection DataGrid is different?

$
0
0

Our application uses WPF DataGrid.

We have use SelectionMode="Extended"

<DataGrid x:Name="gridxxx"
      AutoGenerateColumns="False"
      Style="{StaticResource DataGridStyle1}"
      SelectionMode="Extended"
      SelectionUnit="FullRow"
      ScrollViewer.CanContentScroll="True"
      ScrollViewer.HorizontalScrollBarVisibility="Auto"
      SelectionChanged="DataGrid_SelectionChanged"
      VirtualizingPanel.IsVirtualizing="False"/>

One thing we notice that if we select datagrid rows forward (left mouse click on each row header forward - from top to bottom), for example, select 5 continue rows from row 1 to row 5, we actually only select first two rows (row 1 and row2).

However, if we select datagrid rows backward (left mouse click on each row header backward - from bottom to top), for example, select 5 continue rows from row 5 to row 1, we actually select all 5 rows.

Does anyone know why DataGrid behavior like this?

How can we ensure selection behavior the same no matter select forward or backward? Thx!


JaneC

Viewing all 18858 articles
Browse latest View live


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