I am creating an app in Lightswitch and I used this custom control.
The problem is when I change value of the control.
It's probably not possible to change control dynamically, it must be refreshed to get new value.
So I need to know how can I refresh just control or part of the screen.
This is how the control code look
<Grid x:Name="LayoutRoot" Background="White" Width="200" Height="200">
<GaugeControl:GaugeControl HorizontalAlignment="Left" Margin="10,10,10,10"
Name="gaugeControl1"
Maximum="25000" Minimum="0" VerticalAlignment="Top" />
</Grid>
This way is how I set binding to the value
public RadioGauge() {
InitializeComponent();
gaugeControl1.Value = Amount.amount; // where Amount is class and amount is int property
}
And this way I change the control property
SilverlightCustomControls.Amount.amount = 10000;
I couldnt find anything about refreshing or reloading XAML control or refreshing just part of lighswitch screen.. thx for any help
Lightswitch automatically refreshes components if they are data bound. Because you are just setting the value, the control is not being refreshed. Can you not bind the control to your property? Then when you change it in code the control should automatically refresh?
<Grid x:Name="LayoutRoot" Background="White" Width="200" Height="200">
<GaugeControl:GaugeControl HorizontalAlignment="Left" Margin="10,10,10,10"
Name="gaugeControl1"
Maximum="25000" Minimum="0"
VerticalAlignment="Top"
Value="{Binding Screen.SCREENDATASET.SelectedItem.Amount}" />
</Grid>
Related
Tabbar is a very common navigation control on iOS and Android. But UWP doesn't seem to have.
I've seen an example XamlPivot(SHORTCUT)①, Use Pivot to make TabBar, The effect is very good, and I tried to modify it, so that the TabBar in the bottom, content in the upper.
My project is MasterDetail, Master part is TabBar(i.e TabsStyle Pivot), Detail part just a blank.
Now I found a big problem, TabBar each item does not automatically divide the width, then I try to use data binding and value converters to dynamically provide the width, the binding source is the ActuallyWidth of the MasterGrid, but the ActuallyWidth does not change with the window size, and when the Window on WideState, the Mater part will become blank.
So, How to change the width of the TabBarItem dynamically?
Various window size effect chart(Remove"()"):
(https:)//i.stack.imgur.com/3GE5t.png
(https:)//i.stack.imgur.com/FyQuX.png
(https:)//i.stack.imgur.com/pChwz.png
(https:)//i.stack.imgur.com/cib1l.png
XAML:
<Pivot x:Name="pivot"
Style="{StaticResource TabsStylePivotStyle}">
<PivotItem>
<PivotItem.Header>
<local:TabHeader Width="{Binding ActualWidth, Converter={StaticResource AutoWidthConverter}, ElementName=pivot, Mode=OneWay}"
Glyph=""
Label="item 1" />
</PivotItem.Header>
<TextBlock Text="Content content content" />
</PivotItem>
<PivotItem>
<PivotItem.Header>
<local:TabHeader Width="{Binding ActualWidth, Converter={StaticResource AutoWidthConverter}, ElementName=pivot, Mode=OneWay}"
Glyph=""
Label="item 2" />
</PivotItem.Header>
<TextBlock Text="Content content content" />
</PivotItem>
<PivotItem>
<PivotItem.Header>
<local:TabHeader Width="{Binding ActualWidth, Converter={StaticResource AutoWidthConverter}, ElementName=pivot, Mode=OneWay}"
Glyph=""
Label="item 3" />
</PivotItem.Header>
<TextBlock Text="Content content content" />
</PivotItem>
</Pivot>
Converter:
public object Convert(object value, Type targetType, object parameter, string language)
{
return (double)value / 3;
}
For the record, ActualWidth is NOT a DependencyProperty in UWP XAML model - so can't participate in bindings properly (it doesn't notify of changes).
So if you wish to do a binding like you're doing, you're going to need to expose ActualWidth in a bindable way. One of the easier ways of doing so is to a create a Behaviour explicitly for that, that attaches to the SizeChange event of the target element (in your case the pivot), and returns it's ActualWidth / ActualHeight / RenderSize as DependencyProperties on the behaviour. Your TabItems would then look to the ActualWidth on the behaviour instead.
(It's not done by default presumably because UWP XAML doesn't have read-only dependency property support, and binding too it can easily lead to circular layout cycles when layout rounding is in play if you're not careful)
I have a strange problem with XAML code in Windows Phone 8.1 SL application. I have created a pivot page. So I have something like that:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<phone:Pivot Title="MYAPP">
<!--Pivot item one-->
<phone:PivotItem x:Name="pivotPaliwo" Header="Alcohol" />
<!--Pivot item two-->
<phone:PivotItem Header="Cigarette"/>
</phone:Pivot>
</Grid>
When I drag and drop e.g. a button it creates this code:
<Button Content="Button" HorizontalAlignment="Left" Margin="108,192,0,0" VerticalAlignment="Top"/>
So it is ok. BUT, when I try to add another button (it doesn't matter what control is it) it REPLACES that code for a new one.
I can't add more that one control by dropping from toolbox. Why is that so?
I have Windows Phone 8 page which has a number of controls on it, some of them are LongListSelector controls. If all collections have content everything is displayed correctly.
But if any of the collections bound to the lists are empty all controls below them on the page disappear, i.e. the page looks to be truncated as lots of things are missing.
If I add code to make sure to add at least on item to each collection the page display correctly.
The databinding is done using C#, as shown below.
XAML
<phone:LongListSelector Grid.Row="3" x:Name="PicturesGrid">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Image Source="{Binding Filename}" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
C#
PicturesGrid.ItemsSource = App.ViewModel.SelectedBird.Pictures;
Update: I have noticed that there is a scrollbar present, but however much I scroll I never get down to the bottom.
On my MainWindow.xaml page, I have the following code which works (where MyWord is a string)
<ContentControl Content="{Binding MyWord}" />
I'm playing with DataTemplates and trying understand them. So, I want to reference a DataTemplate from within my ContentControl. The DataTemplate should contain a TextBlock which binds to my string. I updated my code
<ContentControl ContentTemplate="{StaticResource ViewsTemplate}" />
And in my ResourceDictionary I add
<DataTemplate x:Key="ViewsTemplate">
<TextBlock Text="{Binding MyWord}" />
</DataTemplate>
This produces no text on screen at all. I even tried
<ContentControl Content="{Binding MyWord}" ContentTemplate="{StaticResource ViewsTemplate}" />
and still no result on screen.
I can't work out why can any one give some advice please.
Thank you
The ContentControl still needs to have some content bound to it.
<ContentControl ContentTemplate="{StaticResource ViewsTemplate}" Content="{Binding MyWord}" />
Would work, but then you'd need to change your data template because it expects to be able to find MyWord which of course it won't be able to, so you'd want to use just {Binding} instead.
Alternatively, bind the ContentControl's Content to {Binding} - the current DataContext of its parent - and leave the template as it is.
For a windows 8 Apps, i need to put a list of buttons over an image. Each button has CoordinateX and CoordinateY properties. I use a gridView to bind to the list of buttons.
I need to have the result as below:
Here is my code:
<Grid HorizontalAlignment="Left" VerticalAlignment="Top" >
<Canvas>
<Image Source="ms-appx:///Assets/red.png" Stretch="None" ></Image>
<GridView ItemsSource="{Binding Buttons}"
SelectionMode="None" IsSwipeEnabled="false" IsItemClickEnabled="True" ItemClick="Button" Padding="0">
<GridView.ItemTemplate>
<DataTemplate>
<Button Width="194" Height="51" Background="Gray" Canvas.Left="{Binding CoordinateX}" Canvas.Top="{Binding CoordinateY}"></Button>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Canvas>
</Grid>
But this is what i get after running the app:
Ites Likely that at runtime before the X and Y co-ordinates can be set for the items within the GridView, the GridView itself has its properties applied.
Since
1) the GridView is intended to be used for oganization control
and
2) you havent forced the Grid to fill the view space
what you're left with is a GridView that acts as it wishes and limits the ability of its items to conform to your style, should the style attempt to force the items collection to live outside the bounds of the control.
You could try to set the GridView's Horizontal Alignment property but even if it happens to work, its probably a better bet to use a less organized content control like the more basic ItemsPresenter.
Which ever control you end up using... make sure to check for /set the HorizontalContentAlignment & VerticalContentAlignment properties if they exist.