Image tapped inside GridView - c#

I have GridView like this
<GridView ItemsSource="{Binding PublicLibraries}" SelectionMode="None" IsItemClickEnabled="True"
ItemClick="OnPublicLibrariesItemTapped" x:Name="PublicLibrariesGridView"
Margin="24 0" ItemsPanel="{StaticResource LibraryItemsPanelTemplate}"
ItemTemplate="{StaticResource LibraryDataTemplate}" />
and DataTemplate is something like this
<DataTemplate x:Key="LibraryDataTemplate">
<Grid Width="510" Height="300">
<StackPanel Orientation="Horizontal" Background="Black" Opacity="0.8" VerticalAlignment="Bottom">
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Foreground="White"
Text="{Binding LibName}" Margin="12" Width="450"/>
<Image HorizontalAlignment="Left" Margin="12 6" Width="24" Height="36"
Source="ms-appx:///Assets/Logo.png" Stretch="UniformToFill"
Tapped="OnDetailLibraryTapped" />
</StackPanel>
</Grid>
</DataTemplate>
What I want now is when user taps the image it should fire OnDetailLibraryTapped first. But for now when I tap image it still fires OnPublicLibrariesItemTapped. How I can differentiate when user tap the image or the GridView itself?

Related

How to horizontally align controls?

I'm trying to align below controls horizontally by keeping the label and the combobox on the left and both buttons on the right. I've tried different approaches using StackPanel but nothing gives me the desired output. Appreciate if you guys could point out what am I doing wrong here?
Current Layout
XAML source
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Center" Orientation="Vertical" Margin="0,0,0,2" >
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center">
<Label Content="Age Bucket" HorizontalAlignment="Left" VerticalAlignment="Center" />
<ComboBox HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0" Width="100"
SelectedValue="{Binding SelectedAgeBucket}"
DisplayMemberPath="DisplayMember" SelectedValuePath="ValueMember"
ItemsSource="{Binding AgeBuckets}" IsSynchronizedWithCurrentItem="True"/>
</StackPanel>
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal" Margin="0,0,0,2">
<Button Click="Button_Click_1" Content="Export" HorizontalAlignment="Right" />
<Button HorizontalAlignment="Right" VerticalAlignment="Center" Click="Button_Click_2" Content="Print" Margin="5,0" />
</StackPanel>
</StackPanel>
<telerik:RadDataPager x:Name="radDataPager" Source="{Binding Items, ElementName=grdDetails}" PageSize="100" />
</StackPanel>

Cannot find IsChecked property in WPF Checkbox

I have a WPF app with a few checkboxes. I am able to set the IsChecked property in XAML, however, when I go to set it programatically, there is no such property. From everything I read, this property (IsChecked) is how I should be setting the value.
The XAML is below:
<Window x:Class="FC.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="FCSX Utility" SizeToContent="WidthAndHeight" ResizeMode="NoResize" Background="WhiteSmoke" Loaded="Window_Loaded">
<Window.InputBindings>
<KeyBinding Key="N"
Modifiers="Control"
Command="ApplicationCommands.Properties" />
<KeyBinding Key="S"
Modifiers="Control"
Command="ApplicationCommands.Print" />
<KeyBinding Key="L"
Modifiers="Control"
Command="ApplicationCommands.PrintPreview" />
<KeyBinding Key="I"
Modifiers="Control"
Command="ApplicationCommands.CancelPrint" />
</Window.InputBindings>
<TabControl Name="tcTabs" SelectionChanged="tcTabs_SelectionChanged">
<TabItem Name="tciClock" Header="Clock">
<StackPanel Name="spClock" Orientation="Vertical" Margin="0">
<Label FontWeight="Bold">Clock</Label>
<StackPanel Orientation="Vertical" Margin="10">
<StackPanel Orientation="Horizontal" Margin="10">
<Label>Start Time</Label>
<ComboBox Name="cbHour"></ComboBox>
<Label>:</Label>
<ComboBox Name="cbMinute"></ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="10">
<Label>Day Of Week</Label>
<ComboBox Name="cbClockDay"></ComboBox>
</StackPanel>
<Button Name="btnSetClockSystemTime" Click="btnSetClockSystemTime_Click">Set To Current System Time</Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Name ="ckbAlarm1" FontWeight="Bold">Alarm 1</Label>
<CheckBox VerticalAlignment="Center" IsChecked="False"></CheckBox>
</StackPanel>
<StackPanel Name="spAlarm1" Orientation="Vertical" Margin="10">
<StackPanel Orientation="Horizontal" Margin="10">
<Label>Start Time</Label>
<ComboBox Name="cbAlarm1StartHour"></ComboBox>
<Label>:</Label>
<ComboBox Name="cbAlarm1StartMinute"></ComboBox>
<Label>Duration</Label>
<ComboBox Name="cbAlarm1DurationHour"></ComboBox>
<Label>hrs</Label>
<ComboBox Name="cbAlarm1DurationMinute"></ComboBox>
<Label>min</Label>
</StackPanel>
<Label>Days:</Label>
<StackPanel Orientation="Horizontal" Margin="10">
<CheckBox Name="ckbAlarm1Mon">Mon</CheckBox>
<CheckBox Name="ckbAlarm1Tues">Tue</CheckBox>
<CheckBox Name="ckbAlarm1Wed">Wed</CheckBox>
<CheckBox Name="ckbAlarm1Thu">Thu</CheckBox>
<CheckBox Name="ckbAlarm1Fri">Fri</CheckBox>
<CheckBox Name="ckbAlarm1Sat">Sat</CheckBox>
<CheckBox Name="ckbAlarm1Sun">Sun</CheckBox>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label FontWeight="Bold">Alarm 2</Label>
<CheckBox Name="ckbAlarm2" VerticalAlignment="Center"></CheckBox>
</StackPanel>
<StackPanel Name="spAlarm2" Orientation="Vertical" Margin="10">
<StackPanel Orientation="Horizontal" Margin="10">
<Label>Start Time</Label>
<ComboBox Name="cbAlarm2StartHour"></ComboBox>
<Label>:</Label>
<ComboBox Name="cbAlarm2StartMinute"></ComboBox>
<Label>Duration</Label>
<ComboBox Name="cbAlarm2DurationHour"></ComboBox>
<Label>hrs</Label>
<ComboBox Name="cbAlarm2DurationMinute"></ComboBox>
<Label>min</Label>
</StackPanel>
<Label>Days:</Label>
<StackPanel Orientation="Horizontal" Margin="10">
<CheckBox Name="ckbAlarm2Mon">Mon</CheckBox>
<CheckBox Name="ckbAlarm2Tues">Tue</CheckBox>
<CheckBox Name="ckbAlarm2Wed">Wed</CheckBox>
<CheckBox Name="ckbAlarm2Thu">Thu</CheckBox>
<CheckBox Name="ckbAlarm2Fri">Fri</CheckBox>
<CheckBox Name="ckbAlarm2Sat">Sat</CheckBox>
<CheckBox Name="ckbAlarm2Sun">Sun</CheckBox>
</StackPanel>
</StackPanel>
<Button>Apply</Button>
</StackPanel>
</TabItem>
<TabItem Name="tciTrigger" Header="Triggering">
<StackPanel Name="spTrigger" Orientation="Vertical">
<StackPanel Orientation="Vertical" Margin="10">
<Label FontWeight="Bold">Trigger Options</Label>
<StackPanel Margin="10">
<Label>Reset Delay</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
<Label>Arm Delay</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
<Label>Take Delay A</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
<Label>Take Delay B</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10">
<Label FontWeight="Bold">Trigger Sources</Label>
<CheckBox>Internal Motion Sensor</CheckBox>
<CheckBox>External Sensor</CheckBox>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10">
<Label FontWeight="Bold">Pre-Trigger Options</Label>
<CheckBox>Enable Pre-Trigger</CheckBox>
<StackPanel Margin="10">
<RadioButton>Pre-Trigger on Internal</RadioButton>
<RadioButton>Pre-Trigger on External</RadioButton>
<Label>Pre-Tigger Reset Time</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Name="tciDebug" Header="Debug" Visibility="Collapsed">
<StackPanel Orientation="Vertical" Margin="10">
<Label>Command Line Output</Label>
<TextBlock TextWrapping="WrapWithOverflow"></TextBlock>
</StackPanel>
</TabItem>
<TabItem Header="FW Update">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Margin="5" FontSize="14">Welcome!</TextBlock>
<TextBlock Margin="5" FontSize="14">This utility is used to update the firmware of your FC device.</TextBlock>
<TextBlock Margin="5" FontSize="14">Please follow the steps below:</TextBlock>
<Border Margin="2" BorderBrush="Black" BorderThickness="1" Background="White">
<StackPanel Orientation="Vertical" Margin="10,10,10,10" Background="White">
<Image Name="imgUpdate" Source="/FC-Update;component/Update.png" Width="450" Margin="10" Visibility="Visible" />
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Margin="0,0,15,0" Name="lblStep1">Step 1: Connect your FC to the USB port and place<LineBreak/> the jumper in the right position.</TextBlock>
<TextBlock Name="lblStep1Done" Visibility="Collapsed">[DEVICE DETECTED]</TextBlock>
</StackPanel>
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Margin="0,0,15,0" Name="lblStep2">Step 2: Power off the FCand power it back on.<LineBreak/>You should NOT hear any tones but the LED should be lit.<LineBreak/>When done click the 'Continue' button -></TextBlock>
<TextBlock Name="lblStep2Done" Visibility="Collapsed">[DONE]</TextBlock>
<Button Name="btnStep2Continue" Click="btnStep2Continue_Click" Visibility="Hidden" Padding="10,2,10,2" Height="30">Continue</Button>
</StackPanel>
<TextBlock Margin="5" Name="lblStep3">
Step 3: Click 'Choose Firmware Update...', then navigate to the provided .bin firmware update file.<LineBreak/>
After you select the file and click 'Open', the update will start automatically.
</TextBlock>
<Button Name="btnGo" Width="200" Height="30" Margin="10,10,10,5" HorizontalAlignment="Center" HorizontalContentAlignment="Center" IsEnabled="False" Click="btnGo_Click">Choose Firmware Update...</Button>
<TextBlock Name="lblConnect" Foreground="Red" HorizontalAlignment="Center" Visibility="Visible">The 'Choose Firmware Update...' button will only be enabled when<LineBreak/> your FC is connected via the USB cable and has been reset.</TextBlock>
<TextBlock Name="lblPleaseWait" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="OrangeRed" FontWeight="Bold">Please wait...</TextBlock>
<ProgressBar Name="prgMain" Width="200" Height="25" Margin="10,10,10,10" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Visibility="Collapsed" Minimum="0" Maximum="100"></ProgressBar>
<TextBlock Name="lblResetWait" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="Green">The firmware update was downloaded and your device was reset.<LineBreak/>Please keep this window open as we wait to make sure it re-connects...</TextBlock>
<TextBlock Name="lblSuccess" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="Green">The firmware update was successful and your device re-connected!<LineBreak/>Please complete Step 4 and then close this window.</TextBlock>
<TextBlock Margin="5" Name="lblStep4">
Step 4: Once the update completes successfully,<LineBreak/>remove the jumper and unplug the USB cable.
</TextBlock>
<TextBlock Name="lblError" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="Red">The firmware update was NOT successful.</TextBlock>
<TextBlock Name="lblErrorMessage" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="Red" />
<Image Name="imgNoUpdate" Source="/FC-Update;component/NoUpdate.png" Width="450" Margin="10" Visibility="Collapsed" />
<TextBlock Name="lblAllowLuminary" HorizontalAlignment="Center" Visibility="Collapsed" Background="Red" Foreground="White" Margin="10">Will Allow Luminary EPT Devices. Press Ctrl-L Again to Disallow.</TextBlock>
</StackPanel>
</Border>
</StackPanel>
</TabItem>
</TabControl>
</Window>
if (Regex.Matches(alarm1Data.ToString(), "ALARM 1 DISABLED").Count == 1)
{
spAlarm1.IsEnabled = false;
// ckbAlarm1.IsChecked = false; // <--- property not found
}
<Label Name ="ckbAlarm1" FontWeight="Bold">Alarm 1</Label>
ckbAlarm1 is a LABEL !!
I'm using Microsoft Visual C# 2010 Express and had the same problem, but with a different solution. The correct code for this platform is:
this.checkBoxDebugMode.Checked = World.Setup.Debug;
instead of
this.checkBoxDebugMode.IsChecked = World.Setup.Debug;
IsChecked is not a valid property here, but it's what you find when you look it up.

XAML Get data from binded elements

I have this XAML code:
<ListView Name="ListBoxWithNews" ItemsSource="{Binding News}" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding imageURL}" Width="75" Height="75" />
<StackPanel>
<TextBox Text="{Binding Title}" Width="200" />
<TextBox Text="{Binding Body}" Width="200" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The controls are binded using the MVVM pattern. The user can change the content of the two text boxes. Is there a possible way to get the updated text from these text boxes at some point when I need them?
Your ViewModel should implement INotifyPropertyChanged and Use TwoWay Binding as below
<ListView Name="ListBoxWithNews" ItemsSource="{Binding News,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding imageURL,Mode=TwoWay}" Width="75" Height="75" />
<StackPanel>
<TextBox Text="{Binding Title,Mode=TwoWay}" Width="200" />
<TextBox Text="{Binding Body,Mode=TwoWay}" Width="200" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

Fill panorama item dynamically in wp7

I dynamically want to add panorama items in my application. No. of item(3 to 7) is depend on the json response I am getting. Presently for testing I created 4 items in xaml and it works for me but its not dynamic. Here is my xaml.
<Grid x:Name="LayoutRoot">
<controls:Panorama Title="my panorama" Loaded="Panorama_Loaded" Name="title1" ItemsSource="{Binding}">
<controls:Panorama.Background>
<ImageBrush ImageSource="/Images/Panaroma_BG.png"/>
</controls:Panorama.Background>
<!--Panorama item one-->
<controls:PanoramaItem Header="item1" Name="dashboard1" HeaderTemplate="{StaticResource DashBoardName}">
<Grid>
<ListBox Height="512" HorizontalAlignment="Left" Margin="6,8,0,0" Name="listBox1" VerticalAlignment="Top" Width="403" Tap="listBox1_Tap">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Rectangle Height="100" Width="400" HorizontalAlignment="Left" Name="rectangle1" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top"/>
<StackPanel Orientation="Horizontal">
<Image Width="100" Height="100" Source="{Binding Image}" Stretch="Fill" HorizontalAlignment="Left" VerticalAlignment="Top" />
<StackPanel Orientation="Horizontal"
Height="132">
<StackPanel Width="300" HorizontalAlignment="Left">
<Grid>
<TextBlock Text="{Binding CurrentValue}" HorizontalAlignment="Left" FontSize="25" />
<Image Width="20" Height="20" Source="{Binding SubImage}" Stretch="Fill" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
<TextBlock Text="{Binding PreviousValue}" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="15" />
</Grid>
<StackPanel Width="290" HorizontalAlignment="Right" VerticalAlignment="Stretch" Orientation="Vertical">
<TextBlock Text="{Binding ItemName}" FontSize="20" TextWrapping="Wrap" Width="290" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</controls:PanoramaItem>
<!--Panorama item two-->
<!--Panorama item three-->
<!--.................-->
</controls:Panorama>
</Grid>
I don't want to write xaml for Panorama item two, Panorama item three and so on I think there must be some way to do it at runtime. Please help me out.
There must be some template like thing which I can use. and then fill the inner items like CurrentValue , ItemName etc. through code
I have tested below code for pivot. You can implement similar for Panaroma
Dim objPivotItem As PivotItem
Dim sScrollViewer As ScrollViewer
Dim sStackPanel As StackPanel
Dim textHeader As TextBlock
Dim txtContents As RichTextBox
For i = 0 to <Condition>
objPivotItem = New PivotItem
sStackPanel = New StackPanel
sScrollViewer = New ScrollViewer
textHeader = New TextBlock
txtContents = New RichTextBox
'Set TextHeader properties
'Set TxtContents properties
objPivotItem.Content = sScrollViewer
sScrollViewer.Content = sStackPanel
sStackPanel.Children.Add(textHeader)
sStackPanel.Children.Add(txtContents)
objPivot.Items.Add(objPivotItem
)
Next i
You actually can set an ItemsSource property for the whole panorama control, e. g.:
<phone:Panorama x:Name="MyPanorama">
<phone:Panorama.ItemTemplate>
<DataTemplate>
<phone:PanoramaItem Header="MyHeader">
<TextBlock Text="{Binding Text}"/>
</phone:PanoramaItem>
</DataTemplate>
</phone:Panorama.ItemTemplate>
<phone:Panorama.HeaderTemplate>
<DataTemplate>
<TextBlock Visibility="Collapsed" />
</DataTemplate>
</phone:Panorama.HeaderTemplate>
</phone:Panorama>
and then, for example from the code behind:
MyPanorama.ItemsSource = myItemsCollection;

how to acess on controls inside of stackpanel in windows phone7?

i design page bellow code.
<ScrollViewer VerticalScrollBarVisibility="Visible" Grid.Row="1" x:Name="svProduct">
<StackPanel>
<ItemsControl x:Name="lstSearchResult" ItemsSource="{Binding Path=PIProductList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Width="480" Style="{Binding CellStyle}" Orientation="Horizontal" VerticalAlignment="Center" Height="50" >
<TextBlock Foreground="Black" FontSize="20" Width="320" FontFamily="Tahoma" Margin="10,0,0,0" Text="{Binding Title}" VerticalAlignment="Center" TextWrapping="Wrap"></TextBlock>
<Button Name="btnBookmark" Click="btnBookmark_Click" Tag="{Binding}" Background="Transparent">
<Button.Content>
<Image Source="/Images/bookmarks_red.png" Width="33" Height="30" VerticalAlignment="Top" Margin="-15"></Image>
</Button.Content>
</Button>
<Button BorderThickness="0" x:Name="btnSubmit" Click="btnSubmit_Click" Background="Transparent" Tag="{Binding}" >
<Button.Content>
<Image Name="ram" Source="/Images/blue_arrow.png" Width="40" Height="40" VerticalAlignment="Top" Margin="-15"></Image>
</Button.Content>
</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
i want to access for btnBookmark visuble false .
can't access btnBookmark.Visibility=Visibility.collapsed
how to do this?
please help to me...........
The best way I know to do this is to create a Visiblity property on your item ViewModel (the one that is bound to each row in your ItemsControl) and toggle that value based on the changes to each item, presumably via the toggle button in each row. I don't know of a good way to "loop and look" for these internal controls. You're much better off using the existing data binding infrastructure to manage this for you.

Categories

Resources