Dropping control from toolbox replaces previous code - xaml

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?

Related

Button appears all black in dark theme - Windows 11 (WinUi 3)

I am develop a new app for Windows 11 with WinUi 3 and in my MainPage the button appears all black in dark theme:
Why this happen?
This is a resume of my code:
<Window
<Grid Name="Main" RowDefinitions="Auto,*">
<RelativePanel Grid.Row="0"
Background="{ThemeResource SystemControlAcrylicWindowBrush}">
<TextBlock Name="TextBlock_AAA"
Text="AAA">
</RelativePanel>
<RelativePanel Grid.Row="1">
<Button Name="Button_AAA"
Content="AAA"
Click="AAA_Click"/>
</RelativePanel>
</Grid>
</Window>
#Luís, you're putting your UI directly in your window which is why it is not being styled.
Add a Blank Page (from the WinUI tab in VisualStudio) called something like "MainPage" and move your Grid into the XAML for the Page.
In the XAML for your main window, simply put <local:MainPage/> as the only content.
Now your button will look like the one in the comment by #nico-zhu-msft

Empty collection bound to LongListSelector cause incorrect view of page

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.

Refresh custom control Xaml / lightswitch

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>

Button with image and stackpanel with text misses the mouse click event in Windows Store App?

In my Windows Store App I use a button which has a star shape with some text. I use the following XAML code for the button:
<Button Name="goButton" BorderThickness="0" FontWeight="Bold" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,-91,33,0" FontSize="25" IsEnabled="True" Click="goButton_Click" >
<Grid Width="227" Height="222">
<Image Source="Assets/redstar.png" />
<StackPanel Orientation="Vertical" Margin="77">
<TextBlock TextAlignment="Center" Text="Tag"></TextBlock>
<TextBlock TextAlignment="Center" Text="ist um!"></TextBlock>
</StackPanel>
</Grid>
</Button>
This is what is the button looks like:
Unfortunately it often happens that clicks in the area of the star are not recognized, e.g. the event handler is not startet. I suppose that it has something to do with the image, for it works fine if I remove the image from the grid. But this doesn't solve my problem.
Any suggestions?
Don't see anything wrong off the top. You could try a couple of things:
Instead of click, try the Tapped event for the button.
Try tapped on the container Grid.
Get rid of the Grid & put all button content in a StackPanel & then try tapped/clicked on it.
Go with patterns like MVVM & associate your button with a Command.
Hope these help!

Setting Panorama Background for user control in Panorama page

How set the Panorama page Background for User control which is inside the PanoramaItem ?
I had put one user control in Panorama Item. I expect that the same panoroma background is applied to user control, but its not, there is a difference..? how to set the normal Panorama Back ground to the user control which is bound to the panorama item.
<controls:Panorama Grid.Row="1">
<!--Panorama item one-->
<controls:PanoramaItem Header="{Binding Path= Localizedresources.RecentPanoramaItemHeader, Source={StaticResource LocalizedResources}}">
<views:RecentFileView DataContext="{Binding RecentFileViewModel}" />
</controls:PanoramaItem>
<!--Panorama item two-->
<controls:PanoramaItem Header="{Binding Path= Localizedresources.FileserversPanoramaItemHeader, Source={StaticResource LocalizedResources}}">
<views:DashboardView DataContext="{Binding DashboardViewModel}" />
</controls:PanoramaItem>
<!--Panorama item three-->
<controls:PanoramaItem Header="{Binding Path= Localizedresources.MenuPanoramaItemHeader, Source={StaticResource LocalizedResources}}">
<Grid>
</Grid>
</controls:PanoramaItem>
<!--Panorama item four-->
<controls:PanoramaItem Header="{Binding Path= Localizedresources.TheftguardPanoramaItemHeader, Source={StaticResource LocalizedResources}}">
<Grid/>
</controls:PanoramaItem>
</controls:Panorama>
While I am running the application I can see the difference in Back ground of user control. I need the same feel as Panorama not the user control. for that I need the back ground of user control is same as Panorama. - while applying light theam to phone.
I need a transparent background of user control.
I suspect that one (or more) of your UserControls has a Background value set on the root element. The default UserControl that gets added in Visual Studio has the Background property on the root Grid (named LayoutRoot) set: Background="{StaticResource PhoneChromeBrush}", which is not transparent. If you simply remove the Background property, the UserControl will become transparent: <Grid x:Name="LayoutRoot">.