I was careful to check this in the forums, but I did not find a solution.
This works perfect:
<Image Margin="0,0,0,0" Stretch="UniformToFill" Source="http://localhost:5313/Images/1.png" MaxHeight="140" MinHeight="155" VerticalAlignment="Top"/>
Why does this not work:
<Image Margin="0,0,0,0" Stretch="UniformToFill" Source="{Binding ImagenSeleccionada}" MaxHeight="140" MinHeight="155" VerticalAlignment="Top"/>
The code behind.
private string _imagenSeleccionada;
public string ImagenSeleccionada
{
get
{
return this._imagenSeleccionada;
}
set
{
if (this._imagenSeleccionada == value)
return;
this._imagenSeleccionada = value;
}
}
Main Page
The Control
ItemsSource="{Binding FilteredTemperatureReports}" UseLayoutRounding="False"
RowHeight="20" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SelectionMode="Single"
HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent"
Background="{x:Null}" BorderBrush="{x:Null}"
IsFilteringAllowed="False" RowIndicatorVisibility="Collapsed"
CanUserFreezeColumns="False" ShowGroupPanel="False"
HeaderRowStyle="{StaticResource GridViewHeaderRowStyle}"
GroupRowStyle="{StaticResource GridViewGroupRowStyle}"
RowStyle="{StaticResource GridViewRowStyle}">
<telerik:GridViewDataColumn Width="150" DataMemberBinding="{Binding Medio}" IsReadOnly="True" Header="Medio"
HeaderCellStyle="{StaticResource GridViewHeaderCellStyleFirst}"
CellStyle="{StaticResource GridViewCellStyle}" />
<telerik:GridViewDataColumn Width="80" DataMemberBinding="{Binding TimeStamp}" IsReadOnly="True" Header="Fecha" DataFormatString="{} {0:dd/MM/yyyy}"
HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}"
CellStyle="{StaticResource GridViewCellStyle}"/>
<telerik:GridViewDataColumn Width="200" DataMemberBinding="{Binding Producto}" IsReadOnly="True" Header="Producto"
HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}"
CellStyle="{StaticResource GridViewCellStyle}"/>
<telerik:GridViewDataColumn Width="180" DataMemberBinding="{Binding Version}" IsReadOnly="True" Header="Version"
HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}"
CellStyle="{StaticResource GridViewCellStyle}"/>
<telerik:GridViewDataColumn Width="80" DataMemberBinding="{Binding Inversion}" IsReadOnly="True" Header="Inversion" DataFormatString="{}{0:C}"
HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}"
CellStyle="{StaticResource GridViewCellStyle}"/>
<telerik:GridViewDataColumn Width="80" DataMemberBinding="{Binding Ytd}" IsReadOnly="True" Header="YTD" DataFormatString="{}{0:C}"
HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}"
CellStyle="{StaticResource GridViewCellStyle}"/>
<telerik:GridViewColumn Width="80" IsReadOnly="True" Header="Product"
HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}"
CellStyle="{StaticResource GridViewCellStyle}" >
The Code Behin the Grid.
void OnGridViewSelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
{
var grid = sender as RadGridView;
if (grid.SelectedItem != null)
{
grid.ScrollIntoView(grid.SelectedItem);
var _internetDataViewModel = this.DataContext as InternetDataViewModel;
_internetDataViewModel.ImagenSeleccionada = ((ExecutiveDashboard.TemperatureData)(grid.SelectedItem)).Image;
}
}
What is not ok?
Thnaks
The {Binding} does not automatically know where to locate ImagenSeleccionada.
You need to either link it to a specific element, typically your named user control:
<UserControl x:Name="ThisCtrl" .... >
<Image Source="{Binding ImagenSeleccionada, ElementName=ThisCtrl}" ... />
or explicitly set the DataContext of your user control to itself; the DataContext will then propagate down to the user control children:
<UserControl DataContext="{Binding RelativeSource={RelativeSource Self}}" ... >
<Image Source="{Binding ImagenSeleccionada}" ... />
(alternatively you can set the DataContext to this in the code-behind constructor,)
or you can set the relative source of your image binding to the ancestor that is the user control, preferably via its type:
<UserControl ...>
<Image Source="{Binding ImagenSeleccionada,
RelativeSource={RelativeSource AncestorType=local:YourUserControlType}}" ... />
Related
If I go from one page RadGridView to the next (by DataPager) I lose the row selection from the previous page.
This is why if I come back, previously selected items will not be selected anymore.
How can I keep selected rows in RadDataGrid?
Code:
<telerik:RadGridView Margin="5" Grid.Row="2"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
Name="DataGrid"
AutoGenerateColumns="False"
ShowGroupPanel="False"
CanUserDeleteRows="False"
CanUserInsertRows="False"
CanUserFreezeColumns="False"
telerik:StyleManager.Theme="Windows8"
SelectionMode="Extended"
ValidatesOnDataErrors="None"
IsReadOnly="True"
ItemsSource="{Binding View}"
IsBusy="{Binding View.IsBusy}"
RowIndicatorVisibility="Collapsed"
IsSynchronizedWithCurrentItem="False"
FilterOperatorsLoading="DataGrid_FilterOperatorsLoading">
<i:Interaction.Behaviors>
<behaviors:MultiSelectBehavior SelectedItems="{Binding SelectedItems}" />
</i:Interaction.Behaviors>
<telerik:RadGridView.Columns>
<telerik:GridViewSelectColumn/>
<telerik:GridViewDataColumn Header="Производитель" DataMemberBinding="{Binding MakerName}" ShowDistinctFilters="False"/>
<telerik:GridViewDataColumn Header="Номер" DataMemberBinding="{Binding Number}" ShowDistinctFilters="False"/>
<telerik:GridViewDataColumn Header="Наименование" DataMemberBinding="{Binding Name}" ShowDistinctFilters="False"/>
<telerik:GridViewDataColumn Header="Товарная группа" DataMemberBinding="{Binding GroupName}" ShowDistinctFilters="False"/>
<telerik:GridViewDataColumn Header="Вес" DataMemberBinding="{Binding WeightPhysical}" ShowDistinctFilters="False"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<telerik:RadDataPager Height="28" Grid.Row="3"
NumericButtonCount="20"
Margin="5"
Name="DataPager"
Source="{Binding View}"
telerik:StyleManager.Theme="Windows8"
DisplayMode="All"
Style="{StaticResource RadDataPagerStyle}"
AutoEllipsisMode="None"/>
I'm coding a simple windows phone 7.5 localization application.
I've changed the default pushpin template as :
<ControlTemplate TargetType="maps:Pushpin" x:Key="allPushpinsTemplate">
<Grid Height="26" Width="26" Margin="-13,-13,0,0" RenderTransformOrigin="0.5,0.5" >
<Grid.RenderTransform>
<CompositeTransform Rotation="-45"/>
</Grid.RenderTransform>
<Rectangle Fill="Black" HorizontalAlignment="Center" Margin="0" Stroke="White" VerticalAlignment="Center" Height="26" Width="26"/>
<Ellipse HorizontalAlignment="Center" Height="16" Margin="0" VerticalAlignment="Center" Fill="Red" Width="16"/>
</Grid>
</ControlTemplate>
When I click on a pushpin, I handle the event and change the template of the selected pin as :
<ControlTemplate TargetType="maps:Pushpin" x:Key="detailedPushpinTemplate">
<Grid x:Name="ContentGrid" Background="Transparent" Margin="-4,0,0,0">
<StackPanel >
<Grid Background="Black">
<StackPanel Margin="5,5,0,0">
<TextBlock Text="{Binding Adress}" Foreground="White" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ZipCode}" Foreground="White" />
<TextBlock Text="-" Foreground="White" Padding="3,0"/>
<TextBlock Text="{Binding City}" Foreground="White" />
</StackPanel>
<TextBlock Text="{Binding TelStd}" Foreground="White" />
<TextBlock Text="{Binding Email}" Foreground="White" />
<StackPanel Orientation="Horizontal">
<Button BorderBrush="Transparent" Click="Button_Click" CommandParameter="email" ClickMode="Press">
<Button.Content>
<Image Source="/Images/Icons/icon-mail.png" Width="40" Height="40" />
</Button.Content>
</Button>
<Button BorderBrush="Transparent" Click="Button_Click" CommandParameter="phone" ClickMode="Press">
<Button.Content>
<Image Source="/Images/Icons/icon-phone.png" Width="40" Height="40" />
</Button.Content>
</Button>
</StackPanel>
</StackPanel>
</Grid>
<Polygon Fill="Black" Points="0,0 29,0 0,29" Width="29" Height="29" HorizontalAlignment="Left" />
<Grid Height="26" Width="26" Margin="-13,-13,0,0" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left">
<Grid.RenderTransform>
<CompositeTransform Rotation="-45"/>
</Grid.RenderTransform>
<Rectangle Fill="Black" HorizontalAlignment="Center" Margin="0" Stroke="White" VerticalAlignment="Center" Height="26" Width="26" />
<Ellipse HorizontalAlignment="Center" Height="16" Margin="0" VerticalAlignment="Center" Fill="Green" Width="16" />
</Grid>
</StackPanel>
</Grid>
</ControlTemplate>
So that I can display some info and some commands. The result works perfectly and display a black rectangle with all my custom data.
But, the other pins (default template) overlap the rectangle and appears on the top of my selected pin and hide information.
Has anyone an idea to force the selected pin template to be always on top of the other pins ?
for information the XAML of my map :
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Canvas >
<maps:Map ZoomBarVisibility="Visible" ZoomLevel="4" Center="46.8821,2.2697" Name="map1" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Canvas.Top="0" Height="600" Width="460">
<maps:MapItemsControl x:Name="mapControl"/>
<maps:MapItemsControl ItemsSource="{Binding Locations}" >
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<maps:Pushpin Location="{Binding Location}" Template="{StaticResource allPushpinsTemplate}" MouseLeftButtonDown="Pushpin_MouseLeftButtonDown"/>
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
<maps:MapLayer Name="imageLayer"/>
</maps:Map>
<Button Content="some action" Height="70" HorizontalAlignment="Left" Margin="0" Name="button1" VerticalAlignment="Top" Width="170" Canvas.Left="140" />
</Canvas>
</Grid>
The only way I've been able to work around this default behaviour is to remove the original pin and then add a new one in the same position with the different template.
The newly added pin appears at the top in the Z-Order but I haven't been able to alter the Z-Order of existing pins once created.
Also remember to "reset" any pins in the selected state when the user clicks on another.
I guess this should help you: http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/c4055dba-3efd-4bf7-98b3-cd8e24d175ea
y my scrollviewer not scrolling till the end.it gets struck to a limited position.
i hav attached my xaml code.i placed a canvas inside the code.and the scrollviewer is inside 2 grids.
<ScrollViewer>
<Canvas Margin="0,0,0,0">
<toolkit:ListPicker x:Name="listPicker" ItemTemplate="{StaticResource PickerItemTemplate}"
FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}" CacheMode="BitmapCache"
Header="" Margin="12,246,210,298" FontFamily="Yu Gothic" FontSize="22" FontWeight="SemiBold" Width="240" />
<toolkit:ListPicker x:Name="listPicker2" ItemTemplate="{StaticResource PickerItemTemplate}" ItemCountThreshold="3"
FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}" CacheMode="BitmapCache"
Header="" Margin="9,343,210,206" Width="240" />
<toolkit:ListPicker CacheMode="BitmapCache" FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}" Header="" ItemCountThreshold="3" ItemTemplate="{StaticResource PickerItemTemplate}" Margin="12,440,210,108" Name="listPicker1" Width="240" />
<toolkit:ListPicker CacheMode="BitmapCache" FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}" Header="" ItemCountThreshold="3" ItemTemplate="{StaticResource PickerItemTemplate}" Margin="11,546,210,2" Name="listPicker3" Width="240" />
<TextBlock Height="40" HorizontalAlignment="Left" Margin="30,212,0,0" Name="textBlock1" Text="MONTHLY DEBTS" VerticalAlignment="Top" Width="185" FontSize="24" />
<TextBlock Height="40" HorizontalAlignment="Left" Margin="290,212,0,0" Name="textBlock2" Text="AMOUNTS" VerticalAlignment="Top" Width="147" FontSize="24" />
<clrtb:ClearableTextBox Canvas.Left="246" Canvas.Top="242" Height="75" Name="qualifytb" Width="208" />
<clrtb:ClearableTextBox Canvas.Left="242" Canvas.Top="338" Height="75" Name="clearableTextBox1" Width="208" />
<clrtb:ClearableTextBox Canvas.Left="246" Canvas.Top="436" Height="75" Name="clearableTextBox2" Width="208" />
<clrtb:ClearableTextBox Canvas.Left="244" Canvas.Top="542" Height="75" Name="clearableTextBox3" Width="208" />
<TextBlock Text="DEBT RATIO" Canvas.Left="148" Canvas.Top="642" FontSize="26" FontWeight="Medium" />
<TextBlock Text="Conv Debt Ratio:" Canvas.Left="30" Canvas.Top="700" FontSize="26" FontWeight="Medium" />
<TextBlock Text="FHA Debt Ratio:" Canvas.Left="30" Canvas.Top="800" FontSize="26" FontWeight="Medium" />
<TextBlock Text="VA Debt Ratio:" Canvas.Left="30" Canvas.Top="900" FontSize="26" FontWeight="Medium" />
<clrtb:ClearableTextBox Canvas.Left="250" Canvas.Top="700" Height="75" Name="rt1" Width="208" />
<clrtb:ClearableTextBox Canvas.Left="320" Canvas.Top="700" Height="75" Name="rt2" Width="208" />
<clrtb:ClearableTextBox Canvas.Left="250" Canvas.Top="800" Height="75" Name="rt3" Width="208" />
<clrtb:ClearableTextBox Canvas.Left="320" Canvas.Top="800" Height="75" Name="rt4" Width="208" />
<clrtb:ClearableTextBox Canvas.Left="250" Canvas.Top="900" Height="75" Name="rt5" Width="208" />
</Canvas>
</ScrollViewer>
I found this SO question: ScrollBars are not visible after changing positions of controls inside a Canvas, which is basically a similar problem. The question is WPF-specific but can be applied to WP/Silverlight just as well.
The problem is Canvas will always return a DesiredSize of (0, 0), so the ScrollViewer will never think it needs to scroll.
The solution is simple: just use a StackPanel or Grid instead of the Canvas. If you really need the Canvas, you have to override MeasureOverride.
Canvas is not the right layout panel to be using, it's going to produce weird behavior the way you're using it. It's meant to be used when you need finite control over positioning and you are willing to write significant logic to support edge cases that pop up. Try using Grid, and configure it with columns and rows.
I'm currently making a WP7 application with a pivot control. I am making use of a bindable application bar (not the default application bar) because I'm using MVVM in my application. I want to change the application bar displayed, depending on the pivot item I am currently on.
Because I'm using a custom application bar tool, I figured that I could collapse or make visible each application bar depending on which pivot item I'm on, however the application bar will not collapse and only the workout application bar shows in my application (also, is this because I define the workout bar last in my XAML?).
Will this type of tool not collapse?
XAML:
<Grid x:Name="LayoutRoot"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0">
<controls:Pivot Title="{Binding Name}" LoadingPivotItem="pivotMain_LoadingPivotItem">
<controls:PivotItem Header="Details" Name="detailsItem">
<view:EditClientDetails/>
</controls:PivotItem>
<controls:PivotItem Header="Workouts" Name="workoutItem">
<ListBox>
<ListBoxItem>
<view:AddLunch/>
</ListBoxItem>
</ListBox>
</controls:PivotItem>
<controls:PivotItem Header="Diets" Name="dietItem">
<ListBox>
<ListBoxItem>
<view:AddDinner />
</ListBoxItem>
</ListBox>
</controls:PivotItem>
</controls:Pivot>
<!--
<Button FontSize="30" FontFamily="Segoe WP" Content="Add Workout" Height="80" HorizontalAlignment="Left" Margin="25,500,0,0" Name="addWorkout" VerticalAlignment="Top" Width="400" Click="addWorkout_Click" />
<Button FontSize="30" FontFamily="Segoe WP" Content="Add Diet" Height="80" HorizontalAlignment="Left" Margin="25,414,0,0" Name="addDiet" VerticalAlignment="Top" Width="400" Click="addDiet_Click" />
<Button FontSize="30" FontFamily="Segoe WP" Content="Edit Details" Height="80" HorizontalAlignment="Left" Margin="25,328,0,0" Name="editDetails" VerticalAlignment="Top" Width="400" />
-->
<Preview:BindableApplicationBar x:Name="AppBarEdit">
<Preview:BindableApplicationBarIconButton
Command="{Binding AddClientCommand}"
IconUri="/Images/appbar.add.rest.png"
Text="Edit" />
<Preview:BindableApplicationBarIconButton
Command="{Binding SaveClientCommand}"
IconUri="/Images/appbar.check.rest.png"
Text="Save Client" />
</Preview:BindableApplicationBar>
<Preview:BindableApplicationBar x:Name="AppBarDiet">
<Preview:BindableApplicationBarIconButton
Command="{Binding GenerateDietCommand}"
IconUri="/Images/appbar.add.rest.png"
Text="Generate" />
<Preview:BindableApplicationBarIconButton
Command="{Binding SaveDietCommand}"
IconUri="/Images/appbar.check.rest.png"
Text="Save Diet" />
</Preview:BindableApplicationBar>
<Preview:BindableApplicationBar x:Name="AppBarWorkout" Margin="-157,-70,157,70">
<Preview:BindableApplicationBarIconButton
Command="{Binding GenerateWorkoutCommand}"
IconUri="/Images/appbar.add.rest.png"
Text="Generate" />
<Preview:BindableApplicationBarIconButton
Command="{Binding SaveWorkoutCommand}"
IconUri="/Images/appbar.check.rest.png"
Text="Save Workout" />
</Preview:BindableApplicationBar>
</Grid>
Code (just in code behind at the moment for testing purposes):
private void pivotMain_LoadingPivotItem(object sender, PivotItemEventArgs e)
{
if (e.Item == workoutItem)
{
AppBarEdit.Visibility = System.Windows.Visibility.Collapsed;
AppBarWorkout.Visibility = System.Windows.Visibility.Visible;
AppBarDiet.Visibility = System.Windows.Visibility.Collapsed;
}
else if (e.Item == dietItem)
{
AppBarEdit.Visibility = System.Windows.Visibility.Collapsed;
AppBarWorkout.Visibility = System.Windows.Visibility.Collapsed;
AppBarDiet.Visibility = System.Windows.Visibility.Visible;
}
else if (e.Item == detailsItem)
{
AppBarEdit.Visibility = System.Windows.Visibility.Visible;
AppBarWorkout.Visibility = System.Windows.Visibility.Collapsed;
AppBarDiet.Visibility = System.Windows.Visibility.Collapsed;
}
The WP7 UI supports a single ApplicationBar, which is set via the PhoneApplicationPage.ApplicationBar property, the bindable app-bar is a wrapper over the framework class, so it still has this same constraint.
For what you are trying to do, I would just write a bit of code-behind. This does not 'break' the MVVM pattern.
Try setting the IsVisible property of the BindableAppBar. You can have multiple BindableAppBar . However Only one will be displayed at a time. So if you have set IsVisible of two AppBars to false, then the third will be displayed if it is set to True.
<bindableAppBar:BindableAppBar IsVisible="{Binding IsVisible1}">
<bindableAppBar:BindableAppBarButton IconUri="/Assets/AppBar/AppIcon1.png" Text="Text1"/>
</bindableAppBar:BindableAppBar>
<bindableAppBar:BindableAppBar IsVisible="{Binding IsVisible2}">
<bindableAppBar:BindableAppBarButton IconUri="/Assets/AppBar/AppIcon2.png" Text="Test2"/>
</bindableAppBar:BindableAppBar>
I am trying to show a ProgressBar in my Windows Phone 7 app when the app is fetching data.
Here is my XAML:
<!--Panorama item one-->
<controls:PanoramaItem Header="headlines">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Button Name="refresh" Margin="320,-630,0,0" Grid.ColumnSpan="2" Height="75" Width="75" BorderThickness="0" Click="refresh_Click">
<Button.Foreground>
<ImageBrush ImageSource="/DataCollector.Tone;component/Resources/refresh-pressed.png" />
</Button.Foreground>
<Button.Background>
<ImageBrush ImageSource="/DataCollector.Tone;component/Resources/refresh.png" />
</Button.Background>
</Button>
<TextBlock Text="from heraldsun" Margin="12,-30,0,0" Style="{StaticResource PhoneTextSubtleStyle}" Grid.ColumnSpan="2"></TextBlock>
<ProgressBar
Margin="0,-40,0,0"
x:Name="progressBar"
IsIndeterminate="true"
Visibility="Visible" Grid.ColumnSpan="2" />
<ListBox Name="headlines" Margin="0,10,-12,0" ItemsSource="{Binding Tones}" Visibility="Collapsed" Grid.ColumnSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,17,0,17">
<!--Replace rectangle with image-->
<Image Source="{Binding ImageUrl}" Height="75" Width="100" Margin="12,10,9,0" VerticalAlignment="Top" />
<!--<Rectangle Height="100" Width="100" Fill="#FFE5001b" Margin="12,0,9,0"/>-->
<StackPanel Width="311">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!--Double line list with image placeholder and text wrapping-->
</Grid>
</controls:PanoramaItem>
Here is the back end code:
// Load data for the ViewModel Items
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
progressBar.Visibility = Visibility.Collapsed;
headlines.Visibility = Visibility.Visible;
}
}
I recommend using the PerformanceProgressBar from the toolkit.
It runs on the compositor thread, so it won't block with UI things.
In following code:
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
progressBar.Visibility = Visibility.Collapsed;
headlines.Visibility = Visibility.Visible;
}
If App.ViewModel.LoadData() is a synchronous method, thant may be keeping your UI from updating.
Try putting entire MainPage_Loaded code into a seperate method and call it asynchronously.
If I'm reading your most recent comment correctly, the problem you have now is that the value of the visible is initialy true, because the data is loading, and then the binding never occurs again when the data is loaded. I would recommend hooking up to an event (and making it on the data model if need be)
App.ViewModel.OnDataLoaded += (s, e) => performanceProgressBar.Visibility = Visibility.Hidden