spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » WPF » Page 1
Instantiate ViewModel property as element in XAML
I think the correct approach is: <GeometryGroup> <EllipseGeometry ... /> <RectangleGeometry ... /> <MyGeometry Prop1="{Binding Prop1_InViewModel}" Prop2="{Binding Prop2_InViewModel}" ... /> </GeometryGroup> Where Prop1_InViewModel and Prop2_InViewModel are properties of your ViewModel.

Categories : Wpf

How can I bring a Button in a custom control "to the front"?
The reason the button does not react is because you have taken away most of what you would expect a button to have, your button template is just the ContentPresenter, so the button is literally only the textblock. Try <ControlTemplate TargetType="Button"> <Border Background="Transparent"> <ContentPresenter/> </Border>

Categories : Wpf

MahApps NumericUpDown make up down buttons bigger
I am the developer of NumericUpDown in MahApps. A solution is to change in NumericUpDown.xaml the Path.Data in PolygonUp and PolygonDown or to change the Contentent of PART_NumericUp and PART_NumericDown.

Categories : Wpf

Binding of UriSource to BitmapImage not working
Just use the plain string file paths and let the Framework convert them to BitmapImage elements: public string ImagePath { get { return new "F:/myFolder/default.png"; } } ... <Image Height="100" Width="100" HorizontalAlignment="Left" VerticalAlignment="Top"> <Image.Source> <PriorityBinding> <Binding Path="MyModel1.ImagePath"/> <

Categories : Wpf

ValueConverter with multiple arguments
If your Min and Max values never change then you can just have them as properties on the Converter and use a normal IValueConverter to do the conversion, then you are only binding a single value. You can pass values to the converter at creation time like so <UserControl.Resources> <utils:AngleConverter Min="20" Max="2000" x:Key="angleConverter"/> </UserControl.Resources>

Categories : Wpf

ComboBox template issue
ComboBox is an ItemsControl. This means that an ItemsPresenter is expected in the template (at the place where your **StackPanel is). If you want to change the panel the ComboBox uses to render the items, change the ItemsPanel template of the ComboBox.

Categories : Wpf

wpfgfx_0400 makes app hang
From my experience, such errors are almost always a driver issue. You can try to verify that this is hardware/driver related problem by forcing wpf to software render mode - see this answer and this answer for more info on how to do it. If you don't have any problems in software mode then it's a driver issue, so you can try some older driver versions and see if it goes away.

Categories : Wpf

WPF: Always-open Window and Modal Dialoges
If it's just a help window why take the long road? Create a Help project and use its exe file as a separate process. This way the modal window won't block your help window: System.Diagnostics.Process.Start("HelpWindow.exe"); Edit Another workaround is to embed all modal windows within the same window so that only the main content would be prevented from being clicked: <MainWindow>

Categories : Wpf

Creating a Dictionary in xaml code
maybe this can help: Create a Dictionary in xaml? You can't use the Dictionary class directly in XAML, because there's no way to specify the generic type arguments (it will be possible in the next version of XAML, but it won't be supported in VS2010 WPF designer... at least not in the initial release). However, you can declare a non-generic class that inherits from Dictionary, and use it in

Categories : Wpf

Change the text in a TextBox with Text = "{Binding SomeText}" so it is undoable
This works for me: xaml: <UserControl x:Class="TextboxButton.theControl" 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"

Categories : Wpf

WPF - Go To Line in a TextBox
As is stated and what you have found there is no ScrollToCaret in WPF, there is a ScrollToLine method and a CaretIndex method, by combining them I think it will work the way you want it to. See if this works for you Private Sub MoveCaretToLine(txtBox As TextBox, lineNumber As Integer) txtBox.SelectionStart = txtBox.GetCharacterIndexFromLineIndex(lineNumber - 1) txtBox.SelectionLength =

Categories : Wpf

How to bind textbox text to 'current' item of collection
It's quite easy, but there's one thing to be aware of. You can select more than one line in a DataGrid by default and in that case, only one value will show in the textbox. You can change this by setting SelectionMode="Single" on the datagrid. <StackPanel> <DataGrid x:Name="PersonsGrid" ItemsSource="{Binding Persons}" AutoGenerateColumns="False"> <DataGrid.Columns>

Categories : Wpf

Should I always implement INotifyPropertyChanged interface in model?
If you are just displaying in on a DataGrid and not expecting any UI interaction that'll change the value of the Model then you do not have to implement INPC. WPF is tied to the INPC mechanism to update the UI from the backing Model. You don't need it if you load it once and won't change again. However, INPC can be pretty handy and you need to implement it if say a business logic that requires yo

Categories : Wpf

Extending Binding class to provide a bindable converter parameter
tricky when some of the strings (Binding) also require the use of IMultiValue converter. Why not put the intelligence of the string's IMultivalue converter into a specialized class who's ToString() will output the correct string based on the current environmental settings? That would eliminate the need for the sub multivalue converter you describe but work within the framework of the parent M

Categories : Wpf

Set focus to content of ContentPresenter
In fact what you set focus is the ContentPresenter, not the inner TextBox. So you can use VisualTreeHelper to find the child visual element (the TextBox in this case) and set focus for it. However with IsReadOnly being true, you won't see any caret blinking (which may also be what you want). To show it in readonly mode, we can just set IsReadOnlyCaretVisible to true: private void SetFocus(object

Categories : Wpf

Make a columheader in a Listview (GridView) collapse dynamically
This should work just fine. A minimal recreation worked without any problems for me: View Model: public class ListWindowViewModel : INotifyPropertyChanged { private bool _showCompact; public bool ShowCompact { get { return _showCompact; } set { if (value == _showCompact) return; _showCompact = value; t

Categories : Wpf

How to animate opacity of image for a background of a grid but NOT the controls in the grid?
Just detach that parent-child relationship which is pretty simple since you already have it embedded in a Grid; <Window x:Class="george.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> <Grid.RowDefinitions&g

Categories : Wpf

how to use ProgressRing in a WPF application for windows
I don't think your can add a reference to a Windows Store Apps dll to a WPF project, they are built against different versions of the framework. You could however use a ProgressRing from a different WPF targeting dll MahApps Metro has one http://mahapps.com/controls/progress-ring.html (source is on github so you can just take what is needed without having to jump fully into the metro style) Or y

Categories : Wpf

Binding to a Property and also to one of its Properties
Maybe like this <Path Data="{Binding DatGeometry}"> <Path.RenderTransform> <ScaleTransform ScaleX="{Binding Scale}" ScaleY="{Binding Scale}"/> </Path.RenderTransform> </Path>

Categories : Wpf

Understanding dependancy objects
You normally don't want to overwrite DataContext passed through visual tree so you can use either ElementName or RelativeSource binding inside UserControl to change binding context. The easiest way to achive this is give UserControl some name and use it ElementName binding <UserControl ... x:Name="myUserControl"> <!-- ... --> <Grid> <Image Source="{Binding Ico

Categories : Wpf

WrapPanel Horizontal orientation doesn't work
ListView already contains ScrollViewer as part of default template and it's this behaviour that you need to disable by setting attached ScrollViewer.VerticalScrollBarVisibility property to Disabled <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <k:KinectUserViewer Grid.Row="0" Hei

Categories : Wpf

ListView inside ListView + control.Visibility
First add a ValueConverter: public abstract class BaseConverter : MarkupExtension { public override object ProvideValue(IServiceProvider serviceProvider) { return this; } } public class AnswerCollectionToVisibilityConverter : BaseConverter, IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ICollecti

Categories : Wpf

Trigger when condition is not equal to
You need an IValueConverter and some extra markup for this: <Style> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <!--<Condition 1 here.../>--> <!--<Condition 2 here.../>--> <Condition> <Condition.B

Categories : Wpf

How to Resize ListView control when resizing window
Finally i could solve the problem. The key is the information from following link: ItemsControl takes as much space as it needs for its child elements, which can cause it to be larger than the screen. Because its size is based on its child controls, ItemsControl does not resize when re-sizing the screen. So the following xaml part was causing the problem. <TabItem Header="Log" Name="tabLog" B

Categories : Wpf

Is there a way to have blanks for null values in lineseries chart in wpf?
To answer as briefly as you asked, yes. See the BindingBase.FallbackValue Property page on MSDN.

Categories : Wpf

Set style based on variable?
That is exactly what a DataTemplateSelector is designed to do And really the template should be based on the class - not a variable If the customer and vendor have some common properties then have them each implement the common interface

Categories : Wpf

Open Popup with delay when clicking cell
With using RemoveStoryboard action, you need just 1 Storyboard (to show the popup). Also the right event to trigger the Storyboard here is Selected instead of StackPanel.MouseLeftButtonDown: <ControlTemplate.Triggers> <EventTrigger RoutedEvent="Selected"> <BeginStoryboard Storyboard="{StaticResource ShowPopup}" Name="bg"/> </EventTrigger> <EventTrigger Ro

Categories : Wpf

WPF change background of disabled buttons
Possibly more than you were looking for: <Style TargetType="{x:Type Button}" x:Key="ButtonBase"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="Foreground" Value="#FF959595" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="Paddin

Categories : Wpf

WPF DataBinding doesn't work
You are setting the DataContext to an object. The XML attributes are irrelevant at that point. But, if you are trying to create a Cuenta and place it into the list of PrePoliza, then you should use ObservableCollection<T> instead of List<T>, and you need to add the new _cta to the parent collection. If you are binding to a DataGrid each row will bind to the implicit context of the r

Categories : Wpf

WPF pack:/[assemblyName];component/... vs pack://application:,,,/[assemblyName];component/...?
pack:/Common;component/Resources/DefaultTheme/DefaultTheme.xaml This is technically a valid URI, but it is not a valid pack URI. Parsing it according to the rules of the pack format would yield: Package URI: <empty> Part URI: /Common;component/Resources/DefaultTheme/DefaultTheme.xaml In effect, you have made an absolute URI out of a part URI by appending the pack: scheme. However, w

Categories : Wpf

WPF Transform Rectangle in Canvas to Selection in Image
Looks like you need to correct for the DPI difference between the image (usually 72dpi) and the presentation source (usually 96dpi). Additionally, your first Rect should not be offset by Canvas.Left and Canvas.Top; TransformToVisual will take care of the relative offset for you. var source = (BitmapSource)MainImage.Source; var selectionRect = new Rect(SelectionRect.RenderSize); var sourceRect

Categories : Wpf

Laying out ListView Items vertically with uniform size
This will give you a uniform grid as your item host, so they should all uniformly distribute their heights. <ListView> <ListView.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="1" IsItemsHost="True"/> </ItemsPanelTemplate> </ListView.ItemsPanel> </ListView>

Categories : Wpf

XAML Textbox Border when ReadyOnly
Not sure why this could be a problem, but in a basic demo you can just use some Trigger listening to IsReadOnly and set the Border for the TextBox normally: <TextBox IsReadOnly="True" BorderThickness="1"> <TextBox.Style> <Style TargetType="TextBox"> <Style.Triggers> <Trigger Property="IsReadOnly" Value="True"> <Se

Categories : Wpf

How to remove hover style for ListView rows?
In your ListView.Resources, override the ItemBackgroundHover brush resource: <SolidColorBrush x:Key="ItemBackgroundHover" Color="Transparent" /> Do the same for ItemBackgroundSelected if you don't want the selected item to be highlighted. You may also need to override the foreground brushes if you support the Modern Light theme. You can see the brushes that get applied here. This won't

Categories : Wpf

Binding & CustomViewSource applying together in a datagrid wpf
I guess you want to bind to a property of your UserControl. 1) ensure your UserControl itself has a name (usually at the top of your xaml class): <UserControl x:Class="myNameSpace.MyUserControl" x:Name="MyUserCtrl1" ... 2) set binding <Image Source="{Binding ElementName=MyUserCtrl1, Path=ClaimImage}" .. /> Requirements: UserControl.DataContext created Cl

Categories : Wpf

Custom Grid Control
I'm not sure I fully understand the question but you can revise your code using this approach: <StackPanel Grid.IsSharedSizeScope="True"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="col1"/> <ColumnDefinition SharedSizeGroup="col2"/> </Grid.ColumnDefinitions> &

Categories : Wpf

Unit test MVVM commands
At the moment this is not possible as my methods "NewModel" and "SaveModel" are not visible in the unit test which is correct as they're not part of the public interface. And they shouldn't be. You already know the solution to this problem, you even said it yourself: I would like to test the behaviour/result of an command. That's the point. With unit tests we verify observable effects.

Categories : Wpf

WPF TreeView style template resetting IsExpanded on style switch
When you take away a template or replace by another some dependency properties will reset to their default value. The reason for that is dependency property precedence. Take a look at this here: http://msdn.microsoft.com/library/ms743230 Think of it like this: A dependency property may contain many values which are layered. The value in top most layer is always the current value. If you take a st

Categories : Wpf

Button with ControlTemplate does not display in designer
After screwing around with this, I was able to determine that the issue is here: Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" It appears that FindAncestor will not resolve in the designer, resulting in the Stroke being null for all of my drawing.

Categories : Wpf


Recently Add
PropertyChanged is null when binding to static singleton property
Instantiate ViewModel property as element in XAML
How can I bring a Button in a custom control "to the front"?
MahApps NumericUpDown make up down buttons bigger
Binding of UriSource to BitmapImage not working
ValueConverter with multiple arguments
ComboBox template issue
wpfgfx_0400 makes app hang
WPF: Always-open Window and Modal Dialoges
Creating a Dictionary in xaml code
Change the text in a TextBox with Text = "{Binding SomeText}" so it is undoable
WPF - Go To Line in a TextBox
How to bind textbox text to 'current' item of collection
Should I always implement INotifyPropertyChanged interface in model?
Extending Binding class to provide a bindable converter parameter
Set focus to content of ContentPresenter
Make a columheader in a Listview (GridView) collapse dynamically
How to animate opacity of image for a background of a grid but NOT the controls in the grid?
how to use ProgressRing in a WPF application for windows
Binding to a Property and also to one of its Properties
Understanding dependancy objects
WrapPanel Horizontal orientation doesn't work
ListView inside ListView + control.Visibility
Trigger when condition is not equal to
How to Resize ListView control when resizing window
Is there a way to have blanks for null values in lineseries chart in wpf?
Set style based on variable?
Open Popup with delay when clicking cell
WPF change background of disabled buttons
WPF DataBinding doesn't work
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.