Menu
  • HOME
  • TAGS

How to re-height border for windows resize in XAML WPF

Tag: wpf,xaml,height,border

I have a more StackPanels in my XAML. Every StackPanel has a border inside. When I modify the Main Window the width follows the resizing. But the height follows only in one the bigger direction. If I make the Window smaller the height of the borders doesn't follows. So the effect is the Botton border line isn't visible. How can I do this ?

<Window x:Class="MyStackPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyCombobox" Height="356" Width="475">
    <Grid>
        <StackPanel x:Name="STP" 
                Margin="10">
            <Border x:Name="STPB"
                BorderBrush="#FFE80707"
                BorderThickness="5"
                CornerRadius="10"
                Height="{Binding ElementName=STP,Path=ActualHeight}"/>
        </StackPanel>
    </Grid>
</Window>

!border normaly Looks like

Best How To :

Use a Grid instead of a StackPanel then the border will stretch to the

Grids height and width on resizing

<Grid x:Name="STP" 
    Margin="10">
    <Border x:Name="STPB"
        BorderBrush="#FFE80707"
        BorderThickness="5"
        CornerRadius="10" />
    </Grid>

Window after your changes, Looks like the same after reize (make smaller) without your changes.

http://i.stack.imgur.com/SplMn.jpg

How do I provide a collection of elements to a custom attached property?

c#,wpf,binding

I managed to get it working using an IMultiValueConverter like this: public class BorderCollectionConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var borderCollection = new BorderCollection(); borderCollection.AddRange(values.OfType<Border>()); return borderCollection; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { throw new...

In WPF how can I control whether another button clicked

c#,wpf,button,mouseevent

if you want to use same Click handler for two button, try this: private void btnDashboard_Click(object sender, RoutedEventArgs e) { Button btnSender = sender as Button; if(btnSender.Name == "btn1") { //Code for Button1 } else { //Code for Button2 } } Also make sure each button has a Name property...

Enable drag/drop and reordering after long click on GridView control (XAML)

c#,xaml,windows-store-apps

After much fuss and chasing down events, I was able to get the intended effect on pen, mouse, and touch devices. The following code is not guaranteed to be the best way to accomplish the long click drag, but it is functioning on my devices with Windows 8.1. I encourage...

WPF custom button

wpf,button,styles

I'm going to attempt to answer your questions directly, however there is much that can be discussed here. What this template doing? All controls have some kind of default template, a pre-defined look and feel of what the control looks like. The Template is overriding the default look and feel...

Validate a field only if it is populated

c#,wpf,idataerrorinfo

You can implement your OptionalPhoneAttribute based on the original PhoneAttribute: public sealed class OptionalPhoneAttribute : ValidationAttribute { public override bool IsValid(object value) { var phone = new PhoneAttribute(); //return true when the value is null or empty //return original IsValid value only when value is not null or empty return...

Should I be using more than one viewmodel for a database table?

c#,wpf,mvvm

As usual the answer is ain't common, it depends on how you really want to implement it. But for the sake of patterns and organized code, i would recommend that you have: Separate Viewmodel per view: each viewmodel should only contain as many data as many you want to display/work...

System.Windows.Interactivity must be referenced in the main project

c#,wpf,dll,reference

System.Windows.Interactivity.dll is not in the GAC, so .Net doesn't know where to find it. By adding a reference to your main project, you make the build system copy the DLL to the output folder. This lets the runtime find it....

Change Background image in WPF using C# [duplicate]

c#,wpf,image,background,resources

Firstly, add a Folder to your Solution (Right click -> Add -> Folder), name it something like "Resources" or something useful. Then, simply add your desired image to the folder (Right click on folder -> Add -> Existing item). Once it's been added, if you click on the image and...

C# XAML - How to add a combobox to some datagrid ROWS but not others?

c#,wpf,xaml,datagrid,combobox

Try using a DataTrigger with predefined DataTemplate items: <DataTemplate x:Key="OneItem" DataType="{x:Type ValueItem}" > <TextBox Text="{TemplateBinding Id}" /> </DataTemplate> <DataTemplate x:Key="MultiItems" DataType="{x:Type ValueItem}" > <ComboBox ItemsSource="{TemplateBinding ValueItems}" DisplayMemberPath="ValueName" SelectedValuePath="ID" SelectedValue="{TemplateBinding Id}" /> </DataTemplate> And then use a Content control to place the style accordingly. I haven't tried this but your data...

MahApps - How to disable automatic uppercase of default button

wpf,mahapps.metro

You can override the default value by setting the property for all buttons in Window.Resources <controls:MetroWindow ... xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Window.Resources> <ResourceDictionary> <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="controls:ButtonHelper.PreserveTextCase"...

WPF style info from external text file

wpf,vb.net,styles

just hold the color values in a config file simple text file will suffice. though you can use VisualStudio Resource file.. file will contain lines in each: item_enum_name item_type item_value for example: main_screen_bg_color Color Black company_logo URI \logos\logo1.jpg and so on.. just load the file parse it and use bind...

WPF Navigation using MVVM

c#,.net,wpf,mvvm

The AncestorType should be MainWindow not MainViewModel. MainViewModel is not a class that is part of the visual tree.

Add image to the radio button

c#,wpf,xaml

This adds a picture to the background of your radio button. myRadioButton.Content = new Image() { Source = (new ImageSourceConverter()).ConvertFrom( "Images/pic.png") as ImageSource }; ...

TwoWay Binding is not working if Binding is changed from DataTrigger

wpf,datatemplate,datatrigger,2-way-object-databinding

Your answer can be found in the Dependency Property Value Precedence page on MSDN. In short, you have set a local value on the IsOpen property and that has a higher precedence than the value set by the Trigger. The solution is to not set the local value, but to...

while Inherit style in WPF it affect parent style

c#,xaml,styles,wpf-controls

If you declare a Style without an x:Key, it will override the default style for that control. <Style TargetType="local:CustomControl"> So the code above will effect all CustomControl elements throughout the entire application (or within the scope). If you do not want to override the base style, you can give your...

WPF expander not expanded above buttons make buttons unclickable

wpf,xaml,clickable,expander

I found a way of doing it, with code behind. I put my Expander in a Canvas and I added to my Expander two events: Expanded="searchMenuExpander_Expanded" and Collapsed="searchMenuExpander_Collapsed" which are defined as: private void searchMenuExpander_Expanded(object sender, RoutedEventArgs e) { Canvas.SetZIndex(searchMenuCanvas, 99); } private void searchMenuExpander_Collapsed(object sender, RoutedEventArgs e) { Canvas.SetZIndex(searchMenuCanvas,...

Change the Location of DefaultPage in Universal App

c#,xaml,win-universal-app

First, you don't need to give different names to your files, use MainPage for both phone and pc project and put MainPage.xaml inside the view folder. The Universal App will be aware of which platforms it runs on and it will load the right page accordingly. You need to create...

WPF: static INotifyPropertyChanged event

wpf,binding

Instead of a static counter you should have a view model with a collection of Person objects public class ViewModel { public ObservableCollection<Person> Persons { get; set; } } and bind the ItemsSource property of the ListView to this collection. <ListView ItemsSource="{Binding Persons}"> ... </ListView> You could now bind to...

finding file in root of wpf application

c#,xml,wpf,visual-studio,relative-path

First, ensure that the file is definitely copied into your output ./bin/ directory on compile: This worked perfectly for me in my WPF application: const string imagePath = @"pack://application:,,,/Test.txt"; StreamResourceInfo imageInfo = Application.GetResourceStream(new Uri(imagePath)); byte[] imageBytes = ReadFully(imageInfo.Stream); If you want to read it as binary (e.g. read an image...

Open popup at the location of the button clicked

c#,wpf

You can use a Popup control, coupled with it's Placement property to display your popup based on the current location of your buttons. <Popup Placement="Top" PlacementTarget="{Binding ElementName=yourButton}" ... /> Inside your Popup, you can place your UserControl or any content element which will act as the popup's content. See here...

Adding table header to Listview with DataTemplate in XAML

c#,wpf,xaml,listview,windows-runtime

If you have to use ListView then this is how it works: <ListView Margin="120,30,0,120" ItemsSource="{Binding MainViewModel}" Grid.Row="1"> <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding="{Binding Data, Mode=TwoWay}" Width="100" Header="Column 1" /> <GridViewColumn DisplayMemberBinding="{Binding Year, Mode=TwoWay}" Width="100" Header="Column 2" /> <GridViewColumn DisplayMemberBinding="{Binding Month, Mode=TwoWay}" Width="100" Header="Column 3" /> <GridViewColumn...

WPF routedevent storyboard begin only if height is zero

wpf,storyboard,wpf-controls,routed-events

You may use a DoubleAnimation instead of an ObjectAnimationUsingKeyFrames. By only setting its To property, but not From, the animation starts from the current property value. It requires that you also set an initial value of the Height of the Border: <Border Height="20" ...> <Border.Triggers> <EventTrigger RoutedEvent="MouseLeftButtonUp"> <BeginStoryboard> <Storyboard> <DoubleAnimation...

C# Delete Row with Dynamic Textbox/Button/Grid

c#,wpf,button,dynamic,textbox

WPF's ItemsControl is the correct way to show items in your views when the number of items can change. Many controls inherit from ItemsControl, like the ComboBox itself, or the DataGrid, or the ListBox... But in this example I'll use ItemsControl directly, since what you're trying to do doesn't need...

WPF: 2 different label sizes in particular order alignment

wpf,alignment,label

To have such a result, your grid must be really small. I see at least 3 solutions to your issue: 1- Make your grid a bit bigger until it fits. 2- Put 2 columns in your grid, you'd put the number on the left column and the % on the...

CefSharp.Wpf WebView cannot accept input and the link clicked no response

wpf,chromium-embedded

Finally, I got the answer from https://github.com/cefsharp/CefSharp/issues/1080#issuecomment-111969127 I am sorry post the duplicate thread online. With the amaitland's help. I resolved this issue. We just needed remove OnMouseLeftButtonDown method. Thanks for your time....

Binding string lists into wpf listview returns BindingExpression path error

c#,wpf,listview,data-binding

But you aren't binding a list of strings to a ListView, you are binding an IEnumerable<String> to a TextBlock.Text field, when it is expecting a String as you can see in the errors. The fastest way to solve your problem is to change the line to this.AInfoLv.Items.Add(new { Label=" "...

Changing color of positionmarker/caret

wpf,wpfstyle

To modify the color of the caret (which assume is what you call "positionmarker") you have to set the CaretBrush property of the TextBox.

How to print something in WPF without using controls? [closed]

c#,wpf,printing

You can utilize the utilize the PrintDocument class, which is not WPF specific. This class allows you to send output to a printer. The PrintPage event should be handled, where you utilize the PrintPageEventArgs to obtain a Graphics context; which is used to draw the exam to the printer output....

WPF Listbox Collection custom sort

wpf,sorting,listbox,compare,collectionview

You just have to check if it starts with "price". Note that I don't think that ToString() is appropriate; you should rather implement IComparer<T> and strongly type your objects in your listbox. public int Compare(object x, object y) { // test for equality if (x.ToString() == y.ToString()) { return 0;...

Add stack panel when check box is checked

wpf,wpf-controls

What you can do is create the StackPanel in the xaml markup itself with the Visibility set to Collapsed and just toggle the visibility of the StackPanel on the check event of CheckBox

Microsoft Band and WPF

.net,wpf,dll,microsoft-band,.net-core

The current Band SDK does not support Windows desktop (i.e. Win32) applications. It supports only Windows Store and Windows Phone (i.e. WinRT) applications. Portable libraries can be confusing as the terms '.NETCore' and 'netcore451' refer to the Windows Store version of the .NET framework....

WPF add new Slider style cause XamlParseException

wpf,slider,styles

These Styles reference other Styles and Templates via StaticResource: MyFocusVisualStyte (Typo? Shouldn't it be MyFocusVisualStyle?), SliderThumbStyle, SliderRepeatButtonStyle, HorizontalSlider, VerticalSlider... All these Styles and Templates must exist and be defined BEFORE they're used. In this case, the resources must be defined in this order (I'll copy only the first node of...

Is it possible to concactenate a DataBound value with a constant string in XAML DataBinding?

c#,xaml,windows-phone

You can use a StringFormat in your binding, like so: <TextBox Text="{Binding ItemName, StringFormat={}Item: {0}}"/> That being said, it may cause some unexpected behavior when editing. For example, if the user edits only the item name (excluding the 'Item:' text), then when the TextBox loses focus, the string format will...

Why BindingFlags are called so?

c#,wpf,reflection

Because the class that translates the metadata to a actual method is called Binder and BindingFlags are flags that are passed on to the binder to connect to the method.

How to draw something in DrawingVisual with millimeter unit instead of pixels?

c#,wpf,printing,drawingvisual

In WPF, you can't even draw something in pixel units without at least some extra effort. WPF uses "device independent units" where each unit is 1/96th of an inch. Even that is only a theoretical relationship, as it depends on the display device correctly reporting its resolution, which in turn...

Animation Methods, Simplification and Repairing

c#,wpf

Your issue is nothing to do with Animation.The problem is you are comparing sender.Type while you should compare sender itself i.e. use if (sender is TabItem) instead of if (obj is TabItem). Moreover, There is no need to compare sender with TabItem, Lable, Window and etc one by one, they...

Images not appearing on WPF form when loading asynchronously

c#,wpf,multithreading,listbox,backgroundworker

@Clemens answer from his comment on the original question provided the solution. Ensuring that the file stream was being closed responsibly and changing the BitmapCacheOption to OnLoad now shows each image in the asynchronous load. The final code for the asynchronous load looks like: private void LoadAsync(object sender, DoWorkEventArgs e)...

ItemsSource bind to collection stays empty

c#,wpf,xaml,mvvm

In order to observe changes in a collection WPF provides the ObservableCollection class which implements INotifyCollectionChanged and INotifyPropertyChanged. Replace List<T> with ObservableCollection<T> and your code should work.

Images aren't displayed in WPF ListBox

wpf,data-binding,listbox

The binding in the ListBox ItemTemplate should be to the ImageViewModel's ImageBinary property, instead of Images: <DataTemplate> <Border ...> <Image Source="{Binding ImageBinary}" .../> </Border> </DataTemplate> ...

TextBlock hosted inside StackPanel/Grid won't Wrap

wpf

StackPanel stretches accordingly to the size of its content. So if you use Grid and with TextWrapping you can achieve the desired result <Grid> <TextBlock TextWrapping="Wrap" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus leo lectus, viverra ut lobortis vel, mollis eget lectus. Suspendisse laoreet consequat ultrices. Curabitur ultricies,...

Aligning StackPanel to top-center in Canvas

c#,wpf,xaml,canvas

If you don't want any input or hit testing on a certain element you should set the IsHitTestVisible property to false: <Grid> <Canvas Name="Canvas" Background="#EFECCA"> <DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="{Binding ActualWidth, ElementName=Canvas}" Height="{Binding ActualHeight, ElementName=Canvas}" MouseLeftButtonDown="DockPanel_MouseLeftButtonDown" TouchDown="DockPanel_TouchDown" Panel.ZIndex="2" Background="Transparent"> </DockPanel> <Button Width="50" Height="50"...

orderby () containing numbers and letters

c#,wpf,linq,linq-to-sql,sql-order-by

Given your example data where the first number is always a single digit: allScenes.OrderBy(x => x.SceneNumber).ToList() If you can possibly have multi-digit numbers, please provide them and where you want them in the sort order. This is one way to sort multiple digit numbers: var allScenes = new[]{ new {SceneNumber="4B"},...

WPF maximize main window with center for application

c#,wpf,window

Set the WindowState property instead of Width and Height: mainWindow.WindowState = WindowState.Maximized; ...

ContentPresenter in ItemControl.ItemTemplate to show displaymemberpath of itemscontrol

c#,wpf,itemscontrol,contentpresenter

I found an easier way to solve this problem by using horizontal listbox. Thanks for responses