Reference user control command from main application WPF - c#

I am using this code example from live charts
https://lvcharts.net/App/examples/v1/wpf/Constant%20Changes%20II
It's in my application and working however I want to be able to access the "ReadCommand" from outside the user control, implement my own buttons and later send over the values I am reading from the serial port. How can i access the user control from my main application?
I have tried this after looking on various other posts but am struggling to get my head around this.
<Button x:Name="btn_StartTest" Command="{Binding ReadCommand, RelativeSource={RelativeSource AncestorType={x:Type local:GraphData}}}" Grid.ColumnSpan="2" Content="START" Grid.Column="18" Grid.Row="17" VerticalAlignment="Top" Height="43" FontFamily="Arial" Margin="5,0" Click="btn_StartTest_Click"/>

Related

Screen Reader reading disabled button's AutomationProperty.Id

I've added a simple WPF window with two buttons in it.
The buttons are made visible by a certain logic and have bindings which change their Visibility and IsEnabled properties.
Now, I'm testing with windows navigator and seeing that the default windows navigator is reading about the buttons even when they are not visible.
How should I make the button not read by Screen Readers (or windows default navigator) when the button is disabled or not visible?
<Button Margin="0,0,80,10" Height="25" HorizontalAlignment="Right" Name="failedButton"
VerticalAlignment="Bottom" Width="75" DataContext="{Binding InstallationViewModel}"
Command="{Binding Failed}"
Visibility="{Binding Failed,
Converter={StaticResource BooleanToVisibilityConverter}}"
Content="Failed?" />
Automation api reads everything that provide a automation peer. So if you don't want your ui element expose to automation clients, you need to override OnCreateAutomationPeer and return null. And that means, you choose either support automation or not, but you can't change it at runtime.

Implement responsive Master/Detail in UWP using only one page

I would like to know if there's a way to implement a responsive Master/Detail page using only one. What I want is something exactly like the Project here:
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlMasterDetail
Except for the detail that instead of using two pages and navigating from one to another I would only use one page.
Is there a way to do it? If so, could you link me a working example?
Except for the detail that instead of using two pages and navigating from one to another I would only use one page.
After going through the project, I found it implemented a responsive master/detail experience based on the size of the screen. When the app view is sufficiently wide, the master list and detail view should appear side by side in the same app page. However, on smaller screen sizes, the two pieces of UI should appear on different pages, allowing the user to navigate between them. From my point of view, I think this is a good solution for implementing a responsive master/detail experience.
Is there a way to do it? If so, could you link me a working example?
The project already shows how to implement responsive Master/Detail in UWP using only one page, but it implements more and that makes it a little complex to understand. So I make a simple example which directly shows how to implement responsive Master/Detail in UWP using only one page.
Following is the main steps:
First, create a ListView to show master information in xaml page:
<!--Master VIEW-->
<ListView x:Name="ItemListView" Margin="0,0,0,8">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Left" Margin="10,8,0,0">
<TextBlock Text="{Binding Title}" FontSize="25" Width="400" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Second, specify the details view that shows the details item related to the selection on the master list in the same xaml page:
<!--DETAILS VIEW-->
<StackPanel Grid.Column="1" x:Name="ContentPanelDetail" Margin="10,0,0,0" DataContext="{Binding SelectedItem, ElementName=ItemListView}">
<TextBlock Text="{Binding Title}" MaxHeight="80" FontSize="30" HorizontalAlignment="Left" Margin="0" />
<TextBlock x:Name="DetailTextBlock" FontSize="35" Text="{Binding Content}" HorizontalAlignment="Left" Margin="0,18,40,0" Width="500" Height="Auto" TextWrapping="Wrap" />
</StackPanel>
Then, set the ItemsSource for the ListView in code behind:
public MainPage()
{
this.InitializeComponent();
//set the ItemsSource for the ListView
ItemDetails messageData = new ItemDetails();
ItemListView.ItemsSource = messageData.Collection;
ItemListView.SelectedIndex = 0;
}
Last but not least, put Master View and Details View into a SplitView and use VisualStateManager to make it more responsive.
Here is the simple example and the output for your reference.
To implement Master/Detail pattern on your page, you don't have to do it yourself. Instead you can use MasterDetailsView control from UWP Community Toolkit, it does a lot work for you + it is well documented.
Note: For details section of the control, do not set background to null (NoSelectionContent will be visible).

Windows Phone map integration performance issue

I am creating Windows Phone 8 silverlight application and i am using map control with toolkit MapExtensions to bind the pins on the map. But when I navigate away from map screen or come back to this screen it takes normally 2 to 3 sec to load this page. Where as when application is navigating between other non map pages it is fast. How can i improve application performance regarding map load and unload time while navigation. Here is the map control code I am using:
<maps:Map x:Name="map"
Center="{Binding CenterLocation,
Mode=TwoWay}"
CacheMode="BitmapCache"
ColorMode="Light"
Background="White"
>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ResolveCompleted">
<i:InvokeCommandAction Command="{Binding MapResolveCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<tool:MapExtensions.Children>
<tool:UserLocationMarker GeoCoordinate="{Binding CurrentLocation,Mode=TwoWay}"
Width="50"
Height="50"
Style="{StaticResource LocationMapMarker}">
</tool:UserLocationMarker>
<tool:MapItemsControl Name="mapItems">
<tool:MapItemsControl.ItemTemplate>
<DataTemplate>
<tool:MapChildControl GeoCoordinate="{Binding ItemLocation, Converter={StaticResource LocationToGeoCoordinateConverter}}">
<tool:MapChildControl.Content>
<Image
Source="{Binding ItemId,
Converter={StaticResource ImageConverter}}" />
</tool:MapChildControl.Content>
</tool:MapChildControl>
</DataTemplate>
</tool:MapItemsControl.ItemTemplate>
</tool:MapItemsControl>
</tool:MapExtensions.Children>
</maps:Map>
This is to be expected. The map control is a pretty heavy control as there is a lot of moving parts to it. In addition to that, by putting it on a page, every time you move to the page the Map is recreated. What you can do is create a single map and reuse it across all the pages. I wrote a blog post on how to do this for Windows Store apps here: https://rbrundritt.wordpress.com/2014/10/24/be-smooth-optimize-bing-maps-in-multipage-windows-store-apps-javascript/
This was for a JavaScript application so this only shows the concept and would take a decent amount of work to port over.

Save text box data to a local file in a Windows 8 app

I'm learning how to build Windows 8 apps in XAML and I'm somewhat new to it. I have three text boxes and a button on a page and I want to take the text in each text box and save it to a file locally.
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<TextBox HorizontalAlignment="Left" Margin="321,160,0,0" TextWrapping="Wrap" Text="First Name" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Margin="321,211,0,0" TextWrapping="Wrap" Text="Last Name" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Margin="321,260,0,0" TextWrapping="Wrap" Text="Age" VerticalAlignment="Top"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="321,324,0,0" VerticalAlignment="Top"/>
</Grid>
It doesn't really matter what kind of file it is, I'm going to assume a .txt file is fairly easy to create. I've tried to wire up a FileStream on the button click, but intellisense wouldn't allow me to add the necessary usings for it. I'm starting to get the feeling that there is another way you're supposed to handle binary files in Windows 8 apps. If someone could guide me into the right documentation or quickly show me how to set it up, I'd appreciate it.
A fairly easy to use method is File.WriteAllLines as shown in this topic
All you have to do now is retrieve the value from the textboxes. Make sure you assign them a Name property, so you can target them in your code-behind:
<TextBox Name="ageTextBox" HorizontalAlignment="Left" Margin="321,260,0,0" TextWrapping="Wrap" Text="Age" VerticalAlignment="Top"/>
Then in your Code-Behind, say on the button click, add the Text to a list:
List<string> myList = new List<string>();
myList.Add(ageTextBox.Text);
Finally, you write the contents of your list to a specified file:
string path = "D:\\Temp\\MyFile.txt";
File.WriteAllLines(path, myList);
Do note you have to create the eventhandler yourself, name the other textboxes and add their texts to the list too.

I can't get the ToggleSwitch control to appear in my Windows Phone app

I can't get the ToggleSwitch control to appear in my Windows Phone app. The code I'm trying to use is:
<toolkit:ToggleSwitch Header="ToggleSwitch" Height="111" HorizontalAlignment="Left" Margin="7,397,0,0" Name="toggleSwitch1" VerticalAlignment="Top" Width="456" />
or
<controls:ToggleSwitch Header="Test">
<controls:ToggleSwitch.HeaderTemplate>
<DataTemplate>
<ContentControl Content="{Binding}" Foreground="Red"/>
</DataTemplate>
</controls:ToggleSwitch.HeaderTemplate>
</controls:ToggleSwitch>
Neither of which work, and I can't figure out why. It's a C# app that I'm working with.
I think it has to b e a Silverlight app for this to work. Not sure why. I just used a checkbox instead.

Categories

Resources