I need to bind width property of the GridView column that is created dynamically in code.
Since GridViewColumn object has no SetBinding method, how should I do this?
Thanks in advance.
struct Drink
{
public string Name { get; private set; }
public int Popularity { get; private set; }
public Drink ( string name, int popularity )
: this ( )
{
this.Name = name;
this.Popularity = popularity;
}
}
List<Drink> coldDrinks = new List<Drink> ( ){
new Drink ( "Water", 1 ),
new Drink ( "Fanta", 2 ),
new Drink ( "Sprite", 3 ),
new Drink ( "Coke", 4 ),
new Drink ( "Milk", 5 ) };
}
}
So that I can see the Name property for treeview item names.
I have taken the MSDN templates for styling a scrollbar and have been trying to apply my different styles (Image on each track repeater and separate Image on the thumb) but I am unable to make the thumb change size.
I have tried setting the Width on the Track.Thumb style and also in the ControlTemplate of the Thumb itself. For some reason the default size is only ever rendered even when the thumb actually occupies much more space. Does anyone know how to make the thumb render at the size that I want?
The XAML I am using for the styles is here:
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="Background" Value="Red" />
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Image Source="sampleimg.png" Stretch="Fill" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="ArfleHBar" TargetType="{x:Type ScrollBar}">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="18"/>
<ColumnDefinition Width="0.00001*"/>
<ColumnDefinition MaxWidth="18"/>
</Grid.ColumnDefinitions>
<RepeatButton Grid.Column="0" Style="{StaticResource ScrollBarLineButton}" Width="18" Command="ScrollBar.LineLeftCommand" Content="M 4 0 L 4 8 L 0 4 Z" />
<Track Name="PART_Track" Grid.Column="1" IsDirectionReversed="False" >
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" Width="100"/>
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0,1,0,1" Width="250" Padding="0,0,0,0">
</Thumb>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageRightCommand" Width="100" />
</Track.IncreaseRepeatButton>
</Track>
<RepeatButton Grid.Column="3" Style="{StaticResource ScrollBarLineButton}" Width="18" Command="ScrollBar.LineRightCommand" Content="M 0 0 L 4 4 L 0 8 Z"/>
</Grid>
</ControlTemplate>
<Style x:Key="ArfleBar" TargetType="{x:Type ScrollBar}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="Width" Value="Auto"/>
<Setter Property="Height" Value="18" />
<Setter Property="Template" Value="{StaticResource ArfleHBar}" />
</Trigger>
</Style.Triggers>
</Style>
Hello!
I need to define a user control in runtime and then instantiate it wherever I want. So it should not be just a "new UserControl()" (that will be an instance of a UserControl class) but the one I can use as a template. Should I use reflection to generate new type or is there a better way?
Thanks!
Let's say we have a text field named TXTBLAH and a setting named SETTINGBLAH
Is there anyway to write in XAML markup that whenever the text field BLAH gets updated to write that to the registry, and also when the form loads is there a XAML binding to restore it?
The following xaml looks fine in XP, but the bottom of the text gets cut off in Vista and Windows 7.
<Grid>
<Border Height="86"
Margin="10,54,10,0"
VerticalAlignment="Top"
BorderBrush="Black"
BorderThickness="1"/>
<Label Height="22"
Width="100"
Margin="15,43,0,0"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Background="White">Text Over Border</Label>
</Grid>
I realize that I could just increase the Height of the label, but I'm guessing I'll have problems with systems that have different resolution settings, or large text settings. Is there a better way to lay this out?
I need to draw a line with plusses along an given path (arch) but can't seem to find anything pointing me in the right direction.
Any help would me much appreciated.
Best,
Jon H
TextChangedEventArgs is being fired twice in my RichTextBox control.
Is this normal?
Also, when will e.Changes (you know the TextChangedEventArgs) be 1. The only case I can think of is someone pasting content into it.
But other times it seems in normal typing a person can really only change 1 paragraph right?
Hello,
I have several UserControls that have some of the same controls doing the same job.
Is it possible to extract those controls into a base class?
When I have tried it, I get an error that the definition in the generated .g.cs file will hide the parent def.
What I would like to do:
public class ctlBase : UserControl
{
internal CheckBox chkBox { get; set; }
}
In the .xaml of the derived class:
<Grid>
<CheckBox x:Name="chkBox" />
</Grid>
public class DerivedCtl : ctlBase
{ }
Thanks for any insights...
I would like to develop a textbox which restricts special symbols like %. I used textbox's keydown event to restrict '%' . I already used the code as
if(Keyboard.Modifiers == ModifierKeys.Shift && e.key == key.D5)
{
e.handle=true;
return;
}
when i implement this in mvvm architecture, I got problem with the dependency property that recognizes only shift as one key and D5 as another when I converted systemkey into string format.
How can I recognize % symbol?
I have TextBlock in my main form. I set the Text property to different strings during the application run.
I would like to be able to colour parts of particular strings.
Say (pseudo-code)
if(a < 0) txbStatus.Text = string.Format("{0} <RED>{1}</RED>", a, b);
else txbStatus.Text = string.Format("{0} <BLUE>{1}</RED>", a, b);
Hi
There is a list box with some items in it. Also there is a grid with 3x3 matrix. The user will be dragging an item and dropping on one the cells of grid.
Most of the samples I found are about dragging-dropping from one listbox to another listbox. But I want to drop in one cell of grid. How can I achieve this?
Please advise. thanks
PJ
Hi,
I have the following defined in my control:
<local:TestListBox.ItemTemplate>
<DataTemplate>
<Border x:Name="eventBorder" Width="{Binding ElementName=eventsLbx, Path=ActualWidth,BorderBrush="{Binding Color}" BorderThickness="1" CornerRadius="4">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop x:Name="StartGradient" Color="#FFFFFFFF" Offset="0"/>
<GradientStop x:Name="EndGradient" Color="{Binding Color}" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Border.ToolTip>
<ToolTip Content="{Binding Text}"/>
</Border.ToolTip>
<TextBlock TextTrimming="CharacterEllipsis" HorizontalAlignment="Center" FontSize="12" Text="{Binding Text}" />
</Border>
<DataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="eventBorder" Property="Background" Value="#FFE4EBF5"/>
</Trigger>
</DataTemplate.Triggers> -->
</DataTemplate>
</local:TestListBox.ItemTemplate>
</local:TestListBox>
</ScrollViewer.Content>
</ScrollViewer>
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="eventsLbx" Property="HasItems" Value="False">
<Setter TargetName="eventsLbx" Property="Visibility" Value="Hidden"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
Now if there are more items than are visible, then the scrollviewer appears properly but the user CANNOT drag the scrollviewer middle button for scrolling.
The user can click on the arrows at the end of the scrollviewer to scroll but he cannot click the bar that appears on the scrollbar and drag it to actually scroll the contents.
I cannot figure out why this is happening...
Can someone explain this XAML statement, particularly what is the Resolve?
<MenuItem Header="_Load File" Command="{Resolve {Type Commands:LoadFile}}" />
This seems very strange to me.
I know through some adventurous inheritance you can convert most UIElements to a button, but it is a cumbersome way of implementing the most basic of of computer events
I am binding a ListView a property that essentially wraps the Values collection (ICollection) on a generic dictionary.
When the values in the dictionary change, I call OnNotifyPropertyChanged(property). I don't see the updates on the screen, with no binding errors.
When I change the property getter to return the Linq extension dictionary.Values.ToList(), without changing the signature of the property (ICollection) it works with no problem.
Any reason why the Values collection bind and notify properly without projecting to an IList<?
I'm building a simple hex editor in C#, and I've decided to use each cell in a DataGrid to display a byte*. I know that DataGrid will take a list and display each object in the list as a row, and each of that object's properties as columns. I want to display rows of 16 bytes each, which will require a wrapper with 16 string properties. While doable, it's not the most elegant solution. Is there an easier way? I've already tried creating a wrapper around a public string array of size 16, but that doesn't seem to work.
Thanks
*The rational for this is that I can have spaces between each byte without having to strip them all out when I want to save my edited file. Also it seems like it'll be easier to label the rows and columns.
I want an Expander that only expands/collapse it's content when the user clicks on the header icon. (Instead of the whole header being clickable.)
Do I have to redefine the control Template to do this? How would it look like?
Where can I find the standard templates/styles for controls?
Thanks for your time.
In the model, I have:
public ObservableCollection<Item> Items { get; private set; }
In the ViewModel, I have a corresponding list of ItemViewModels:
public ObservableCollection<ItemViewModel> ItemViewModels ...
In the XAML, I will bind (in this case a TreeView) to the ItemViewModels property.
My question is, what goes in the "..." in the ViewModel shown above? I am hoping for a line or two of code to binds these two ObservableCollections (providing the type of the ViewModel to construct for each model object). However, what I'm fearing is necessary is a bunch of code to handle the Items.CollectionChanged event and manually updates the ItemViewModels list by constructing ViewModels as necessary.
Thanks!
Eric
I've run into a case where I have a custom Panel (inherits from Panel) and I'm using it as an ItemsPanel in a ListView.
When I resize the container that it's in, if I resize it smaller, my panel's MeasureOverride function gets called once, but if I resize it larger (let's say from 100 to 300), it calls MeasureOverride and ArrangeOverride for every value between 100 and 300, in increments of 2 (so 102, 104, etc.).
The weird thing is that the container resizes right away (its size gets to 300 immediately).
It doesn't seem to matter what I return from MeasureOverride - it just does this.
I wish I could make it happen in a really small application and post it here, but I haven't been able to reproduce it like that yet. I can reproduce it all day in my app though.
Does anyone know what could cause this?
I want to position a modal dialog (progress window) at the top right corner of the parent window client area.
This code will put it in the corner of the non-client area, but how do I calculate the offset to the client area?
this.Owner=owner;
this.Left=owner.Left+owner.ActualWidth-Width;
this.Top=owner.Top;
Edit:
I found this 'solution' that works for normal windows:
this.Left=owner.Left+owner.ActualWidth-Width-SystemParameters.ResizeFrameVerticalBorderWidth;
this.Top=owner.Top+SystemParameters.ResizeFrameHorizontalBorderHeight+SystemParameters.WindowCaptionHeight;
This would however fail for windows that have customized borders.
EDIT:
The code should work regardless of the systems DPI setting (e.g. 120 instead of 96).
So say for example I created a few small squares in expression blend.
I then group them together by selecting them, right clicking and selecting "Group Into - Grid"
So now that they are in the grid, I'd like to be able to resize this grid and then they would resize but it doesn't happen, it just resizes the grid but leaves the vectors the same.
Is there a way to do what I am looking for?
p.s I know you can just select all the vectors and then resize them all, but I am looking for a way to just resize one container and not all the objects in there..
Hello Experts!
I'm trying to do a periodic separated thread operation let's say check for internet connection or check for user's info via web service and update the user interface.
i've tried with quartz.net to implement that.So i created an inner class for the window i need to update.That inner class does what is meant for but the problem is that i don't know how to access parent's(window class) members form the child(inner class). for example
public partial class Window2 : Window
{
private int i;
public Window2()
{ InitializeComponent();
}
public string doMyOperation()
{
//code here
return result;
}
public class Myclass :IJob
{
public void Execute(JobExecutionContext context)
{
string result = doMyOperation();
//Now here i could be able to call a label of name lblNotif
//lblNotif.Content = result;
}
}
}
Well the whole idea works but i'm stacked at here i need to access a controls of Window2
Since i'm stacked i tried Spring.Net way of implementing Quartz hoping that i could use MethodInvokingJobDetailFactoryObject and rather have the Operation done on Window2 itself.But for some reason i'm having an exception
Cannot resolve type [System.Windows.Window2,System.Windows];, could not load type from string value System.Windows.Window2,System.Windows
and the wiring is done so
<object name="UpdateLabelJob" type="System.Windows.Window2,System.Windows"/>
What i'm i doing wrong here?Is that a way round? thanks for reading and for helping out
In the program I am trying to build, I have a menu button that opens a second window. The user puts information into the second window, presses the "Done" button, and the information is transfered into the main window. The problem I am having is opening the second window. I have both windows build in xaml files in Visual Studio but I can't find a way to show the second window. Using "Window window = new Window" does not fit my needs because 1) I already have the second window built and 2) I have tried this and I cannot figure out how to add children to the window; there is no window.children nor any grid to put the children into. Thank you in advance!
Here's the problem.
Given a large/intricate datatemplate A, which has 3 sections - General, Properties, Misc.
Imagine 3 grids for each.
Now I need to reuse the Properties section of the above Datatemplate in another place. Reasons: To avoid redundancy + ensure that further updates to the datatemplate are applied identically to all usages.
So I guess what I am asking for is an ability to slot in a link to a child DataTemplate in a parent Datatemplate. What's the best way to go about this ?
I found one way to do this.. but I'm not sure if its the right way or the best.. Posting it as an answer below so that it can be rated.