|
Hi Gerry,
Thanks for your quick reply , same thing is happening if i use
IsEnabled="{Binding ElementName=listBoxDraftVersions, Path=SelectedItems.Count}" on button.
But i want button to be enabled when only 1 checkboox is checked else it should be diabled if >1 and <1
Thanks and Regards
|
|
|
|
|
"IsEnabled" is a bool; simply trying to bind it to SelectedItems.Count (an int) is not going work.
You might be able to use a "converter" in there ...
(Or just change the trigger to "enable" the button if the "count" is 1; using a default of "not enabled").
|
|
|
|
|
Hi Gregg,
In that case i am not able to select multiple checkboxes. i want to select multiple checkboxes also but using this cannnot select multiple only one is getting checked at one time.
Thanks
|
|
|
|
|
To select multiple items, the "SelectionMode" for the ListBox should be set to "Multiple".
If you are going to ignore the "built-in" selection logic of the ListBox and associated items, then you will have to use your own custom code.
Your approach is wrong.
Your are using checkboxes to "select" items in a listbox; instead, you should simply use the checkbox to "display" the "selected" status of a given item and use the built-in selection logic as it was intended.
(Gary, Larry, Gerald, George and now Gregg ... My level of visibility is now tracking in the minus range).
|
|
|
|
|
I'm trying to bind the ListBoxItem's IsSelected property to a property called 'IsItemSelected' on my base entity.
<Style x:Key="listBoxItemContainerStyle"
TargetType="ListBoxItem">
<pre>
<Setter Property="IsSelected" Value="{Binding IsItemSelected}"/>
This isn't working. The selected item's IsItemSelected property is not being set.
What am I missing here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
A couple of ideas, first what is the listbox items source? Make sure that the object in the items source should have a boolean property "IsItemSelected" and that would be the property that you bind the value to, not the view model.
I made a sample object that had two properties, string Name and bool IsItemSelected
I added that to an observable collection (yourList) and then I define the ListBox and the container style as such
<ListBox ItemSource="{Binding yourList}" DisplayMemberPath="Name">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected"
Value="{Binding IsItemSelected}"/>
If this is not working then the fault might be in your view model, things to make sure are are you implementing INotifyPropertyChanged? Is your event set up correctly? If this is still not working and you would like to post your view model I would be happy to help.
Cheers!
|
|
|
|
|
I have one datagrid, inside that datagrid have taken one combobox. I am trying to create the SelectionChanged event for this combobox but its not working. Below is the code:
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<StackPanel Orientation="Horizontal">
<cc:MyComboBox Name="ddlDepositMode" Width="150" ItemsSource="{Binding DataContext.ModeCollection, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" DisplayMemberPath="ModeName" SelectedValuePath="ModeId" IsSynchronizedWithCurrentItem="False" SelectedValue="{Binding Path=ModeId,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Path=ModeName, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Padding="3,0,0,0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding DataConext.ModeTypeCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</cc:MyComboBox>
</StackPanel>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
|
|
|
|
|
Ashfaque Hussain wrote: DataConext.ModeTypeCommand
Shouldn't that be DataContext.ModeTypeCommand ?
If it still doesn't work, check the Output window in Visual Studio for binding errors.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have taken checkbox on the header of the DataGrid, but Boolean property of IsChecked is binding.
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<StackPanel>
<cc:MyCheckBox Width="30" IsChecked="{Binding Path=MyViewModel.IsAllSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ></cc:MyCheckBox>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
|
|
|
|
|
Check the output window in Visual Studio for binding errors.
The Path=MyViewModel.IsAllSelected doesn't look right. Does the DataContext for the grid's parent really have a property called MyViewModel ? Are you sure it shouldn't just be Path=IsAllSelected ?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have tried with all the possibilities for the Path property:
Path=DataContext.IsAllSelected
Path=IsAllSelected
Path=MyViewModel.IsAllSelected
none of these are working
|
|
|
|
|
Try doing it like this,
...
<cc:MyCheckBox Width="30" IsChecked="{Binding Path=IsAllSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}">
...
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
Thanks Meshack, but this approach is not working
|
|
|
|
|
I overlooked something. It should be DataContext.IsAllSelected . This should work,
<cc:MyCheckBox Width="30" IsChecked="{Binding Path=DataContext.IsAllSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}">
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
Hello Everyone,
I am facing issue in binding data to my controls. I am not able to implement below 2 scenarios:
1) whenever i am updating my textbox text my view model is not listening the change.
2) i also want to update my other 2 textbox text property based on the value of first textbox.
Kindly help me on this one.
here is my View
<Window x:Class="iPLAN20.Windows.LS.frmLinkApplicationSite"
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 ="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:local="clr-namespace:iPLAN20.Model.LS"
xmlns:stb="clr-namespace:UIControls;assembly=iPLAN20UIControls"
Title="Link Information" Height="260" Width="320" Loaded="Window_Loaded" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Window.Resources>
<local:clsAppSiteLinkModel x:Key="AppSiteModel"/>
</Window.Resources>
<Grid HorizontalAlignment="Left" Name="gridLandSafeguardingLink" DataContext="{StaticResource AppSiteModel}">
<Grid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\..\Resources\ButtonStyle.xaml"/>
<ResourceDictionary Source="..\..\Resources\textbox.xaml"/>
<ResourceDictionary Source="..\..\Resources\Common.xaml"/>
<ResourceDictionary Source="..\..\Resources\ComboBox.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Label Content="Site No.:" HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource ASCIILabelStyle}" Grid.Row="0" Grid.Column="0"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1">
<TextBox Text="{Binding Path=AppSiteList, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}" stb:AutoCompleteBehavior.AutoCompleteItemsSource="{Binding AppSiteList}" AutoWordSelection="True" Width="190" Name="txtSearchAppSite" TextAlignment="Center" Margin="10,4,4,4" VerticalContentAlignment="Center" Grid.Column="1"/>
<Button IsDefault="True" x:Name="btnFind" Style="{StaticResource MetroButton}" Margin="1" Width="30" Height="30">
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="/IPLAN20;component/Images/Search.png" Width="12"/>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
<Label Grid.Row="1" Grid.Column="0" Style="{StaticResource ASCIILabelStyle}" Content="Choose Site:" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<ComboBox Grid.Row="1" Grid.Column="1" Style="{StaticResource ComboBoxStyle}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,4,4,4" Width="220" ItemsSource="{Binding LinkOID}"></ComboBox>
<Label Grid.Row="2" Grid.Column="0" Style="{StaticResource ASCIILabelStyle}" Content="Status:" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtStatus" Width="220" Grid.Row="2" Grid.Column="1" Style="{StaticResource TextBoxStyle}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,4,4,4" Text="{Binding AppSiteListColl[0].AppSiteStatus}"/>
<Label Grid.Row="3" Grid.Column="0" Style="{StaticResource ASCIILabelStyle}" Content="Description:" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtDescription" Height="100" Grid.Row="3" Grid.Column="1" Style="{StaticResource TextBoxStyle}" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Margin="10,4,4,4" Text="{Binding AppSiteListColl[0].AppSiteDescription}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="4" Grid.Column="1">
<Button Content="Link" IsDefault="True" x:Name="btnLink" Style="{StaticResource MetroButton}"/>
<Button Content="Close" IsDefault="False" x:Name="btnCancel" Style="{StaticResource MetroButton}"/>
</StackPanel>
<!--<WindowsFormsHost>
<wf:ListBox x:Name="lstBox"/>
</WindowsFormsHost>-->
</Grid>
</Window>
and my view model
class clsAppSiteLinkModel:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
clsLandSafeguarding objLandSafeguarding = new clsLandSafeguarding();
private ObservableCollection<string> _collAppSiteListForLink = new ObservableCollection<string>();
private ObservableCollection<clsSearchAppSiteLink> objObCollAppSiteForLink = null;
public ObservableCollection<string> AppSiteList
{
get { return _collAppSiteListForLink; }
set
{
_collAppSiteListForLink = value;
FirePropertyChanged("AppSiteList");
}
}
public ObservableCollection<clsSearchAppSiteLink> AppSiteListColl
{
get { return objObCollAppSiteForLink; }
}
private ObservableCollection<string> _collOID = new ObservableCollection<string>();
ObservableCollection<clsObjectId> objObCollOID = null;
public ObservableCollection<string> LinkOID
{
get { return _collOID; }
}
public clsAppSiteLinkModel()
{
if (iPLANConstants.Instance.Workspace == null)
{ return; }
objObCollAppSiteForLink = objLandSafeguarding.GetAppSiteForLink();
//Selecting Application site No's from MV_IPLAN_EPACS
if (objObCollAppSiteForLink != null)
{
foreach (clsSearchAppSiteLink appSiteNo in objObCollAppSiteForLink)
{
this.AppSiteList.Add(appSiteNo.AppSiteNo);
}
}
objObCollOID = objLandSafeguarding.GetNewSiteOID();
//Selecting feature OID's from file geodatabase
if (objObCollOID != null)
{
foreach (clsObjectId objctID in objObCollOID)
{
this.LinkOID.Add(objctID.ObjectIds);
}
}
}
private void FirePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
whenever txtSearchAppSite text gets changed based on the value txtStatus and txtDescription changed their values. All data is there under objObCollAppSiteForLink observable collection and loaded(Working fine)
Thanks and Regards
|
|
|
|
|
Why are you binding your TextBox 's Text property to a ObservableCollection<string> ?
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
Rather binding Textbox's text property to ObservableCollection I would suggest create string property and binding it with text property of "txtSearchAppSite" and on basis of that value you can write logic to change the value of "txtStatus" and "txtDescription".
Let me know if it works for you.
Regards
|
|
|
|
|
what is Silver Light ??? and Purpose actully where it use..
|
|
|
|
|
Forget it, Silverlight is a deprecated framework and has no future use.
It was framework that allowed a developer to use a single technology to deploy responsive web applications that rivalled the desktop user experience. We are left with a dogs breakfast of different frameworks, scripts, CSS and javascript FFffaaaaarrrrkkkkkk!!!!!!!!!!!!!!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I have a problem setting an image to a nested menu item (sub menu).
On top level it is working:
<Menu SnapsToDevicePixels="True" VerticalAlignment="Top">
<MenuItem Header="File">
<MenuItem.Icon>
<Image Source="{Binding ElementName=imgTest, Path=Source}"/>
</MenuItem.Icon>
</MenuItem>
</Menu>
The Image and the text are shown.
Now I do:
<Menu SnapsToDevicePixels="True" VerticalAlignment="Top">
<MenuItem Header="File">
<MenuItem Header="Exit">
<MenuItem.Icon>
<Image Source="{Binding ElementName=imgTest, Path=Source}"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
The sub menu is shown without the image. What do I am missing.
In both cases imgTest is defined as:
<Image Margin="3, 3, 3, 3" Name="imgTest">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="#FF000000" Geometry="M48.915604,39.796998L49.232002,41.73309 18.511999,46.738 18.197001,44.801911z M26.696344,37.951999C27.351365,40.044217,30.231,41.092324,30.231,41.092324L25.910998,42.530999z M26.878857,31.266772L26.9972,33.22778 15.219097,34.475999 15.012001,32.525582z M34.563435,20.119521L32.862622,22.185774 12.228199,23.391999 12.115,21.430711z M36.7463,10.928L36.801003,12.889913 9.3190308,13.674999 9.2630005,11.713086z M48.612541,6.759L48.645159,6.8475333C49.62698,9.3927367,51.956423,12.657845,56.185604,13.352003L56.397999,13.383851 37.033453,37.166108 32.585721,37.558 29.444799,34.677852 29.182,30.360229z M39.522339,5.2349992L42.135407,10.839494 40.334999,13.107881 40.304173,13.145332 37.950729,7.982356 4.0573845,8.1138562 14.78915,52.345605 54.832485,45.017514 47.395187,28.701589 49.447243,26.521901 59.413,47.896409 11.255238,57.579999 0,5.3651915z M54.178093,0C62.421474,0.65496874,62.031075,6.8060206,62.031075,6.8060204L58.233984,11.515564C51.559698,11.778664,50.122002,4.972653,50.122002,4.9726532z">
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
Anyone?
I still say the magic word: Immediately! Okay - "please" of course!
Best Regards
Martin
|
|
|
|
|
If I were you, I'd look to convert your image into a Style like this:
<Style x:Key="LocalImageStyle" TargetType="{x:Type Image}">
<Setter Property="FlowDirection" Value="LeftToRight"/>
<Setter Property="Source">
<Setter.Value>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="#FF000000" Geometry="M48.915604,39.796998L49.232002,41.73309 18.511999,46.738 18.197001,44.801911z M26.696344,37.951999C27.351365,40.044217,30.231,41.092324,30.231,41.092324L25.910998,42.530999z M26.878857,31.266772L26.9972,33.22778 15.219097,34.475999 15.012001,32.525582z M34.563435,20.119521L32.862622,22.185774 12.228199,23.391999 12.115,21.430711z M36.7463,10.928L36.801003,12.889913 9.3190308,13.674999 9.2630005,11.713086z M48.612541,6.759L48.645159,6.8475333C49.62698,9.3927367,51.956423,12.657845,56.185604,13.352003L56.397999,13.383851 37.033453,37.166108 32.585721,37.558 29.444799,34.677852 29.182,30.360229z M39.522339,5.2349992L42.135407,10.839494 40.334999,13.107881 40.304173,13.145332 37.950729,7.982356 4.0573845,8.1138562 14.78915,52.345605 54.832485,45.017514 47.395187,28.701589 49.447243,26.521901 59.413,47.896409 11.255238,57.579999 0,5.3651915z M54.178093,0C62.421474,0.65496874,62.031075,6.8060206,62.031075,6.8060204L58.233984,11.515564C51.559698,11.778664,50.122002,4.972653,50.122002,4.9726532z">
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Setter.Value>
</Setter>
</Style>
Then, change your MenuItem.Icon to this:
<Image Style="{StaticResource LocalImageStyle}"/> And that's it - you can reuse your style whereever you like.
|
|
|
|
|
Thanks a lot! Works great!
|
|
|
|
|
|
Possibly related to this SO thread[^] - it's a ContextMenu rather than a Menu , but I suspect the root cause is the same.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have a window with 2 anchorable panes (one left and one at the bottom) and a documentPane. I use MVVM.
So I set the DocumentsSource and AnchorablesSource properties of DockingManager. The collection in AnchorablesSource
only binds to the left anchorable pane. I do not how to bind models to the second anchorable
How do I have to set up the xaml so that I have control over the binding of the anchorable panes?
Thanks in advance
Marc
|
|
|
|
|