I have a Popup which contains an ItemsControl (I can use ListBox if needed) which its items are arranged horizontally.
Since the total width of the items can exceed the width of the screen, I need to limit the size of the popup width.
My question is how can I limit the size of the popup? I've tried to use MaxWidth, but it doesn't work :(
<Popup x:Name="puSoldItems" IsOpen="False" IsLightDismissEnabled="True" MaxWidth="{Binding ActualWidth, ElementName=_This}" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto">
<Grid Background="#f8202020" MaxWidth="{Binding ActualWidth, ElementName=puSoldItems}">
...
...
...
<ItemsControl x:Name="icItems" Grid.Row="1" Background="Transparent" Margin="10" MaxWidth="{Binding ActualWidth, ElementName=puSoldItems}" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto">
...
...
...
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Padding="0" Margin="0 0 0 10" BorderBrush="#afafaf" BorderThickness="0 0 0 1" MinWidth="350">
...
...
...
<local:UPSoldItemList ItemsSource="{Binding Items}"></local:UPMenuModifier>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Popup>
Thanks...
I partially solve this problem by forcing the width.
Here is what I did; I add ScrollViewer and put ItemsControl inside. Then when open the popup, I set the size of the ScrollViewer
private void btnItem_Tapped(object sender, TappedRoutedEventArgs e)
{
svItems.MaxWidth = this.ActualWidth - 100; //for padding (50 left & 50 right)
svItems.MaxHeight = this.ActualHeight - 80; //for padding (40 top & 40 bottom)
puSoldItems.IsOpen = true;
}
Is anyone has a better solution, please kindly post it here.
Thanks!
Related
I am trying to show percentage value on radial chart, but radial chart's percentage property only allow me to display value between 0 and 100.
How can I do this?
Having a view with id__xmlview0,
and a chart with id RadialMicroChart1:
$("#__xmlview0--RadialMicroChart1 > svg > text").text(yourText)
It will work even if you have several charts.
SAP does not allow values over 100% for Radial Micro Charts, you could try setting the value using JQuery and manipulating fraction and total to fit your case.
Using the charts unique id for the first chart chartRadial1 to get it's element.
Update:
Bare in mind that, depending on the layout of your view, the children might change and you would have to research more into nth and children selectors to make sure you are selecting the right one but for this example its the svg's 6th child.
var percent = $(".sapSuiteRMCFont");
percent.text("200%");
OR In Controller & View:
press: function(oEvent) {
var myVal = 150,
myTotal = 200,
actTotal = 100,
newVal = (myVal * actTotal) / myTotal;
this.getView().byId("chartRadial1").setPercentage(newVal);
//with the given id in xml view, you can be certain only the text for chartRadial1 will change using child selector
setTimeout(function() {
$("div#__xmlview2--chartRadial1 > svg.sapSuiteRMC.sapSuiteRMCSizeResponsive.sapSuiteRMCNeutralTextColor :nth-child(6)").text(myVal + "%");
}, 500);
}
div#__xmlview2--chartRadial1>svg.sapSuiteRMC.sapSuiteRMCSizeResponsive.sapSuiteRMCNeutralTextColor :nth-child(6) {
font-family: fantasy !important;
}
div#__xmlview2--chartRadial2>svg.sapSuiteRMC.sapSuiteRMCSizeResponsive.sapSuiteRMCNeutralTextColor :nth-child(6) {
font-family: arial !important;
}
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="sap.sample.Detail" xmlns:semantic="sap.m.semantic" xmlns:c="sap.suite.ui.microchart">
<content>
<Label text="6.25rem x 6.25rem" width="12.5rem" class="sapUiSmallMargin" />
<FlexBox width="6.25rem" height="6.25rem">
<items>
<c:RadialMicroChart id="chartRadial1" size="Responsive" percentage="99" press="press"></c:RadialMicroChart>
</items>
</FlexBox>
<FlexBox width="6.25rem" height="6.25rem">
<items>
<c:RadialMicroChart id="chartRadial2" size="Responsive" percentage="99" press="press"></c:RadialMicroChart>
</items>
</FlexBox>
</content>
</mvc:View>
I am using syncfusion datagrid in my xamarin.forms application. I used 2 picker in 2 columns of sfdatagrid.
how can I set selectedindex = 0 of 2nd picker on selectedindexchanged event of 1st picker.as Icoudnt find its refence in my event.pls help.
You can achieve your requirement by binding CLR property with int type to Picker.SelectedIndex property for both Picker, like in the below code example.
C#:
Model:
private int selectedindex;
public int Selectedindex
{
get
{
return selectedindex;
}
set
{
selectedindex = value;
RaisePropertyChanged("Selectedindex");
}
}
XAML
<sfgrid:GridTemplateColumn MappingName="Picker1" >
<sfgrid:GridTemplateColumn.CellTemplate>
<DataTemplate>
<Picker TextColor="Black"
SelectedIndex="{Binding Selectedindex, Mode=TwoWay}" >
<Picker.Items>
<x:String>1</x:String>
<x:String>2</x:String>
</Picker.Items>
</Picker>
</DataTemplate>
</sfgrid:GridTemplateColumn.CellTemplate>
</sfgrid:GridTemplateColumn>
<sfgrid:GridTemplateColumn MappingName="Picker2" >
<sfgrid:GridTemplateColumn.CellTemplate>
<DataTemplate>
<Picker TextColor="Black"
SelectedIndex="{Binding Selectedindex, Mode=TwoWay}" >
<Picker.Items>
<x:String>3</x:String>
<x:String>4</x:String>
</Picker.Items>
</Picker>
</DataTemplate>
</sfgrid:GridTemplateColumn.CellTemplate>
</sfgrid:GridTemplateColumn>
Please refer the below sample for more details:
Sample link: http://www.syncfusion.com/downloads/support/directtrac/169982/ze/XamarinForms1797267025
Regards,
Ashok
So As you can see the ID column should be hidden but its not. And the debugger is showing the value of IDVisible in the xaml file to be "Hidden" but it never makes it to the window. I am calling a property changed method as well. What am I doing wrong, the ID column should disappear or at least that's what I am trying to do.
And here is the code for MainWindowViewModel.cs
namespace MagicDB
{
class MainWindowViewModel : ObservableObject
{
private CardDB _cards;
private Command _InitCardDB;
private Visibility _IDVisible;
public CardDB Cards
{
get { return _cards; }
set { _cards = value; OnPropertyChanged("Cards"); }
}
public Visibility IDVisible
{
get { return _IDVisible; }
set { _IDVisible = value; VerifyPropertyName("IDVisible"); OnPropertyChanged("IDVisible"); }
}
public MainWindowViewModel()
{
IDVisible = Visibility.Hidden;
_InitCardDB = new Command(InitDB, true);
Cards = new CardDB();
}
And the xaml file....
<Window x:Class="WpfDataGrid.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Width="500" Height="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="450*" />
</Grid.RowDefinitions>
<DataGrid AutoGenerateColumns="False"
HorizontalAlignment="Left"
Name="dataGrid1"
VerticalAlignment="Top"
ItemsSource="{Binding Cards.cardDB}"
CanUserReorderColumns="True"
CanUserResizeColumns="True"
CanUserResizeRows="False"
CanUserSortColumns="True"
AlternatingRowBackground="LightBlue"
Width="480" Height="auto" Grid.Row="1" IsSynchronizedWithCurrentItem="True"
>
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding CardID}" Width="25" Visibility="{Binding IDVisible,Mode=TwoWay}"></DataGridTextColumn>
I would check your Visible binding as it is most likely failing. This page explains a few methods that you can use. I personally prefer adjusting the trace level.
I believe the reason that the binding is failing is due to the fact that your DataContext (I assume you have set it somewhere) isn't getting to the DataGrid's columns themselves. This page explains a fix that I have used in the past to solve this problem. I think I originally found that article from this page that has several other good to know WPF 'Gotchas'.
I’m using .Net 4.0 DataGrid with MVVM pattern. I need to enable user to select cells and copy information from selected cells to other DataGrid rows (either via keyboard shortcut or context-menu copy/paste). I tried to achieve this via SelectedItem or sending SelectedItem as CommandParameter but this functions only with the whole row and not with cells.
(DataGrid is bound to ObservableCollection that contains objects with float fields. These fields are then mapped to DataGrid cells)
So, is there any solution in WPF MVVM how to copy DataGrid cells from one row to another?
Thanks in advance
xaml:
<DataGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="9" AutoGenerateColumns="False" Height="Auto" HorizontalAlignment="Left"
Name="dataGrid" VerticalAlignment="Top" Width="{Binding ElementName=grid4,Path=Width}"
ScrollViewer.CanContentScroll="False" FrozenColumnCount="1" SelectionUnit="Cell" SelectionMode="Extended" CanUserSortColumns = "False"
CanUserReorderColumns="False" CanUserResizeRows="False" RowHeight="25" RowBackground="LightGray" AlternatingRowBackground="White"
ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible"
ItemsSource="{Binding Layers, Mode=TwoWay}" SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Selection, Mode=TwoWay}">
<DataGrid.InputBindings>
<KeyBinding Gesture="Shift" Command="{Binding ItemHandler}" CommandParameter="{Binding ElementName=dataGrid, Path=SelectedItems}"></KeyBinding>
</DataGrid.InputBindings>
ViewModel:
private float _selection = 0.0f;
public float Selection
{
get
{
return _selection;
}
set
{
if (_selection != value)
{
_selection = value;
NotifyPropertyChanged("Selection");
}
}
}
...
public DelegateCommand<IList> SelectionChangedCommand = new DelegateCommand<IList>(
items =>
{
if (items == null)
{
NumberOfItemsSelected = 0;
return;
}
NumberOfItemsSelected = items.Count;
});
public ICommand ItemHandler
{
get
{
return SelectionChangedCommand;
}
}
I think you might be after the SelectionUnit property. Setting this to CellOrRowHeader changes the selection method from full row to a single cell.
You do lose the nice "what row am I on?" highlighting but you are focusing on a single cell. (You could probably extend the datagrid to add your own highlight with the current row logic.)
<DataGrid AutoGenerateColumns="True" Grid.Column="1" Grid.Row="0"
HorizontalAlignment="Stretch" Name="dataGrid" VerticalAlignment="Stretch"
DataContext="{Binding}" ItemsSource="{Binding Path=MyDataTable}"
IsReadOnly="True" SelectionMode="Extended" SelectionUnit="CellOrRowHeader" />
I am a seasoned C and Java programmer, but an absolute WPF newbie.
I am creating a kiosk application that will display a list of images of products that the user will click to see product details and maybe place an order.
I am trying to structure my app with MVVM Foundation because I am used to the benefits of structure and tests.
I wonder what is the most natural way to create a grid of clickable images that will fill the screen left to right, top to bottom (or the other way round, I have no exact requirements).
Any image should be bound to an object that will become current and be displayed in the next screen.
Thanks for your help.
OK! Listen up! Here is how you do that! :)
1) Use ItemsControl together with UniformGrid to get automatic aligment
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid>
</UniformGrid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<Button Width="50" Height="50"/>
<Button Width="50" Height="50"/>
<Button Width="50" Height="50"/>
</ItemsControl>
2) Populate ItemsControl with data from your viewmodel
<ItemsControl ItemsSource="{Binding Path=ImageList}"...
public ObservableCollection<ClickableImage> ImageList
{
get { return m_ImageList;}
}
... constructor
{
m_ImageList = new ObservableCollection<ClickableImage>();
m_ImageList.Add(new ClickableImage("image.png");
}
TADAAAA!
I have refined a little the code. Here is the namespace declaration
xmlns:vm="clr-namespace:TestSandbox.ViewModels"
the DataContext
<UserControl.DataContext>
<vm:ViewModel1/>
</UserControl.DataContext>
and the uniformGrid
<ItemsControl Name="imageList" ItemsSource="{Binding Path=Products}" BorderBrush="#FFA90606" Background="#FFE70F0F">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Margin="50">
</UniformGrid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- The Image binding -->
<Image Source="{Binding Path=image}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
here is the C# code in the view model
public List<Product> Products {get; set; }
public ViewModel1()
{
Products = new List<Product>();
Products.Add(MakeProduct(#"..\images\beemovie.jpg"));
Products.Add(MakeProduct(#"..\images\darkknight.jpg"));
Products.Add(MakeProduct(#"..\images\matrix.jpg"));
Products.Add(MakeProduct(#"..\images\milo.jpg"));
Products.Add(MakeProduct(#"..\images\superhero.jpg"));
Products.Add(MakeProduct(#"..\images\twilight.jpg"));
Products.Add(MakeProduct(#"..\images\xfiles.jpg"));
}
public Product MakeProduct(string path)
{
return new Product(path, MakeImage(path));
}
public BitmapImage MakeImage(string path)
{
BitmapImage bmpi = new BitmapImage();
bmpi.BeginInit();
bmpi.UriSource = new Uri(path, UriKind.Relative);
bmpi.EndInit();
return bmpi;
}
In ViewModel add ObservableList<ClickableImage> m_Images as public property.
In XAML use ListView for displaying ClickableImage.
Create datatemplate for ClickableImage with Image and raised command uppon click.
On the XAML:
<Button Command="{Binding Path=OnClickCommand}"/>
On the ViewModel:
public ICommand OnClickCommand {
get
{
return new RelayCommand(aram => this.Click(), param => this.CanClick);
}
}
public void Click() {
//i was clicked!
globalBigImageViewModel.BigImageContent = m_Image;
}