|
|
Yes I am. Learning is a team sport.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
I'm trying to style a tab item like this[^].
So I copied this style into my view, but I don't understand how to apply this. Where/how in the TabControl XAML do I use this?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Put it into a Resources section and drop the x:Key part to have it automatically applied to the TabItem elements.
|
|
|
|
|
Ok, so that sorta worked. I get the button, but not the header text
If it's not broken, fix it until it is
|
|
|
|
|
[UPDATE] Found it..
I have a listbox with hyperlinks as the list items. But the selected item is a blue bar with white text. I'd like to remove the highlighting. Here's what I have so far:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type TreeViewItem}">
<Style.Triggers>
<Trigger Property="IsMouseCaptureWithin" Value="True">
<Setter Property="IsSelected" Value="True" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate DataType="{x:Type models:JobModel}">
<StackPanel Orientation="Horizontal"
Margin="2">
<Image Source="/FMG.UI.WPF;component/Media/Images/job_72.png"
Height="16"
Width="16"
Margin="0,0,3,0"/>
<controls:TextBlockEx>
<Hyperlink Style="{StaticResource linkStyle}"
Command="{Binding SelectedJob, Mode=TwoWay}">
<TextBlock Text="{Binding JobNumber}"/>
</Hyperlink>
</controls:TextBlockEx>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
and
<ListBox Grid.Row="1"
Grid.Column="0"
ItemsSource="{Binding Jobs}"
SelectedItem="{Binding SelectedJob}"
BorderThickness="1"
BorderBrush="#6593CF"
Margin="-1,0,-1,-1">
<ListBox.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Background" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.Resources>
</ListBox>
Can someone show me how to remove the selected item's fore & back color so it ddoesn't appear selected?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
<pre lang="text">
1.How to bind the MenuItem Command of ListBoxItem ContextMenu dynamically?
2. How to set its CommandParameter?
//----------------------------------
//MainWindowView.xaml
//----------------------------------
<Window x:Class="MVVM.Views.MainWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:vm="clr-namespace:MVVM.ViewModels"
Title="MainView" Height="354" Width="520">
<Window.DataContext>
<vm:MainWindowViewModel/>
</Window.DataContext>
<Grid>
<!--In this ListBox, the MenuItem command can not be called-->
<ListBox Height="252" HorizontalAlignment="Left" Margin="12,51,0,0" Name="listBox1" VerticalAlignment="Top" Width="201"
ItemsSource="{Binding Path=TestItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Width="150">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Call Command1" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding Command1}" CommandParameter="???"/><!--here the Command1 not be called-->
</i:EventTrigger> <!--how to set command parameter to this ListBoxItem displaying text?-->
</i:Interaction.Triggers>
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!--In this ListBox, the menuitem command can be called,
but the command parameter can not be set correctly-->
<ListBox Height="252" HorizontalAlignment="Left" Margin="230,51,0,0" Name="listBox2" VerticalAlignment="Top" Width="229"
SelectedItem="{Binding SelectedText,Mode=OneWayToSource}">
<ListBoxItem>
<TextBlock Text="item1" Name="tb" />
<ListBoxItem.ContextMenu>
<ContextMenu>
<MenuItem Header="Call Comand1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<!--this one can be called correctly,
but the command parameter can not be set correctly-->
<i:InvokeCommandAction Command="{Binding Command1}" CommandParameter="{Binding ElementName=tb,Path=Text}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
</ContextMenu>
</ListBoxItem.ContextMenu>
</ListBoxItem>
<ListBoxItem>
<TextBlock Text="item2"/>
<ListBoxItem.ContextMenu>
<ContextMenu>
<MenuItem Header="Call Comand1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding Command1}" CommandParameter="" />
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
</ContextMenu>
</ListBoxItem.ContextMenu>
</ListBoxItem>
</ListBox>
<Label Content="This one can not work" Height="28" HorizontalAlignment="Left" Margin="12,25,0,0" Name="label1" VerticalAlignment="Top" />
<Label Content="This one can work" Height="28" HorizontalAlignment="Left" Margin="230,25,0,0" Name="label2" VerticalAlignment="Top" />
<Label Content="Test ListBox ContextMenu" Height="28" HorizontalAlignment="Left" Margin="12,0,0,0" Name="label3" VerticalAlignment="Top" />
</Grid>
</Window>
//------------------
//MainWindowViewModel.cs
//---------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows;
using System.Windows.Controls;
using MVVM.Command;
namespace MVVM.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
public List<string> TestItems
{
get
{
return new List<string>()
{
"Item1",
"Item2",
"Item3"
};
}
}
public ListBoxItem SelectedText
{
get;
set;
}
public MainWindowViewModel()
{
}
private ICommand _command1;
public ICommand Command1
{
get
{
if(null==_command1)
{
_command1 = new DelegateCommand<string>((str) =>
{
MessageBox.Show("Command1 with parameter:" + str+((TextBlock)SelectedText.Content).Text);
});
}
return _command1;
}
}
ICommand _command2;
public ICommand Command2
{
get
{
if (null == _command2)
{
_command2 = new DelegateCommand<Button>((button) =>
{
if (null == button)
return;
Point p = Mouse.GetPosition(button);
button.Content = string.Format("{0},{1}", p.X, p.Y);
});
}
return _command2;
}
}
}
}
</pre>
|
|
|
|
|
You have to either bind it to a property in your list item object, or to a static property or hard code it. In your case, you can also just specify "{Binding}" in the command parameter and it will pass in the actual object.
|
|
|
|
|
Thank you very much, SledgeHammer01.
My issue is the ListBox1 MenuItem Command binded in ListBoxItem ContextMenu MenuItem does not work. But MenuItem Command in ListBox2 can work well.
I don't know why. In my project, I need dynamically bind the menu itms just like in ListBox1 used.
Could you please help check it? thanks a lot.
|
|
|
|
|
Oh... I see what you are asking. Yeah, you're doing it wrong in both cases. You should use the ItemsSource property of the listbox to set the collection of items. There is no need to use the ItemTemplate if all you are doing is showing a TextBlock as that is the default behavior. You should specify the context menu on the ListBoxItem, not the TextBlock. Then you can use {Binding} to pass in the item itself, but it will not be necessary as the sender will be the item.
|
|
|
|
|
Thanks a lot.
I'm newer for WPF binding. I tried and tried again. And the MenuItem command in listbox1 still can not be fired.
|
|
|
|
|
Well, post your corrected code.
|
|
|
|
|
Do you have email? I can send you my demo version to you. Thanks a lot.
my email is neighbornet@163.com
|
|
|
|
|
how do we use expression blend???? can you send me some sample programms using expression blend????
aishu
|
|
|
|
|
"mm" is not a very good title for a question; try putting something meaningful. As to Expression Blend, follow the link I gave you in your other question and find it in MSDN.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
what is the use of silverlight??? how do we use that in asp.net????
aishu
|
|
|
|
|
Start here[^]. You could also look at these articles[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I am trying to change the appearance of a control when the value of a property changes. I am using the XAML and C# code below, but nothing happens when I click on the button that changes the value of the Property myProperty, except when I first run the application. Any suggestions?
<Window x:Class="WpfApplication3.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>
<Button Height="34" HorizontalAlignment="Left" x:Name="toggleBroadcast" VerticalAlignment="Top" Width="133" Margin="180,0,0,0">
<Button.Style>
<Style x:Name="bb" TargetType="{x:Type Button}">
<Setter Property="Content" Value="Original Content"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=myProperty}" Value="true">
<Setter Property="Content" Value="IS TRUE"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=myProperty}" Value="false">
<Setter Property="Content" Value="IS FALSE"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Content="Click on This Button" HorizontalAlignment="Left" Width="158" Click="Button_Click_1" Height="34" VerticalAlignment="Top"/>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
{
public partial class MainWindow : Window
{
Boolean _Check = false;
public MainWindow()
{
DataContext = this;
InitializeComponent();
}
public Boolean check
{
get
{
return _Check;
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
_Check = !_Check;
}
}
}
|
|
|
|
|
There are a couple of things wrong with your code here. The first thing is that you don't have to supply both true and false DataTrigger elements. Add one of those triggers as the default content. When the bool value goes to the default value, the style trigger is removed.
Now, as to why you aren't seeing the value change. Even though you are changing the value, you aren't telling the XAML that the value has changed. Make this class implement INotifyPropertyChanged and have your code raise the PropertyChanged event when the vale changes. This raises the change notification.
Oh, and you aren't binding to check in your example. You are binding to myProperty.
|
|
|
|
|
First of all, you have not done any binding to your Check Property, binding to myProperty will not help you at all. You need to change your binding to bind to the Check property. Secondly for bindings to react to changes in the bound property you need to implement the INotifyPropertyChanged[^] interface in you viewmodel/code behind. Try this code :
<Grid>
<Button Height="34" HorizontalAlignment="Left" x:Name="toggleBroadcast" VerticalAlignment="Top" Width="133" Margin="180,0,0,0">
<Button.Style>
<Style x:Name="bb" TargetType="{x:Type Button}">
<Setter Property="Content" Value="Original Content" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Check}" Value="true">
<Setter Property="Content" Value="IS TRUE" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Check}" Value="false">
<Setter Property="Content" Value="IS FALSE" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Content="Click on This Button" HorizontalAlignment="Left" Width="158" Click="Button_Click_1" Height="34" VerticalAlignment="Top" />
</Grid>
public partial class MainWindow : Window,INotifyPropertyChanged
{
Boolean _check = false;
public MainWindow()
{
DataContext = this;
InitializeComponent();
}
public Boolean Check
{
get
{
return _check;
}
set
{
if (_check != value)
{
_check = value;
OnPropertyChanged("Check");
}
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Check = !Check;
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
We have a scene designer in our app that allows the user to add elements and resize, rotate, and position them.
When the user tries to resize to make the adorned element shorter, the adorner reaches a certain size and stops getting smaller (both vertically and/or horizontally), but the adorned element continues to get smaller.
I've looked and looked, but can't find anything that resembles a minimum height or width property.
There's a LOT of code associated with this problem (the adorner class is 525 lines all by itself, and then there's the xaml for the thumbs), so I'm not real fond of the idea of posting ALL of the code at once unless it's absolutely necessary.
Can anyone provide guidance?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
There is a MinHeight and MinWidth, but it should be undefined by default. This is one of those "look around at random sh*t until you stumble across the issue" type problems . I'd start at figuring out what size the adorner stops working at. Is it the same for height and width? Is it some arbitrary number like 47.488484 or is it something system metric-y like 32? Once you have figured out the height and width that the adorner stops shrinking at, I'd rack your brain and look through the code to try to figure out where those numbers are coming from. I'd also put diagnostic messages in all the adorner layout calculation functions to see what sizes & points are coming in and what size & points you are returning and what you are doing with your visuals. Also check that the mouse messages are being processed as expected.
|
|
|
|
|
Actually, it's got something to do with RenderSize on the adorned element. I thought I had it figured out today when I overrode OnRender , and set the render size in there, but when I do something else (like drag, resize, or rotate), the RenderSize goes back to its original value, but then immediately reverts to it's set size (because I set it in OnRender ). Furthermore, the rotation code STILL uses the (wrong) render size values to set the center of the rotate transform.
I hate WPF. If you think it would be worth it, I could post my adorner code (but like I said before, there's a LOT of it).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
You usually just override the MeasureOverride and the ArrangeOverride methods. Those two methods have to return the correct sizes and arrange everything properly for the adorners to work right.
|
|
|
|
|
I have a requirement where I am using a datagrid and the number of columns will not be known until runtime. I found the following article and was able to get it working.
http://elegantcode.com/2010/03/08/silverlight-datagrid-populate-dynamic-columns-from-a-child-collection/
However this solution uses the XamlReader and creates a datatemplate in the code behind. I am not entirely happy with this solution. Is there another way that I can achieve the same result without using the XamlReader. Essentially im trying to achieve something like this
CellTemp.Append(String.Format("<TextBlock Text='{{Binding Periods[{0}].{1}}}'/>", index, propertyName)); but instead of using the XamlReader create this binding in in xaml.
modified 17-Dec-12 0:34am.
|
|
|
|
|