WPF Control remove focus and hover effect (FocusVisualStyle?!) - wpf

I am trying to remove the nasty looking effect on controls when hovering or focusing.
This seems not to work:
FocusVisualStyle="{x:Null}"
And this is what I got so far:
<ComboBox Grid.Row="2" HorizontalAlignment="Right" Background="Transparent" BorderBrush="#FFE87E00" FocusVisualStyle="{x:Null}"/>
Thanks in advance!

Look at the control template, you should be able to manipulate what occurs when visual states changes from there.

Related

ListView ReorderMode XAML

I'm stuck in a problem about WP8.1:
I have a ListView with ReorderMode = "Enabled"; so it is draggable and the user can reorder the list by dragging.
The problem is that when a listview is inside the ReorderMode state, its items become smaller, ther opacity diminishes, and the items are constantly moving around!! I'm looking for a way to avoid these secondary effects of the ReorderMode.
Everything would be much easier if the properties CanDragItems, CanReorder and AllowDrop worked in WP8.1, but it seems that they do not...
Does Anyone have any idea about how to prevent this behaviour from happening?
<ListView x:Name="SitesListContainer"
DataContext="{Binding RouteResultsVM.SelectedRoute.PlacesNotCurrentPosition, Mode=TwoWay}"
ItemsSource="{Binding}"
HorizontalContentAlignment="Stretch"
Background="{x:Null}"
SelectionChanged="SitesListContainer_SelectionChanged"
Grid.ColumnSpan="2">
Thank you in advance!
I have not tested this but try to get the default listview datetemplate and remove <ReorderThemeTransition /> that might work. here is the link ListView Default style

Getting blur text only if the window is not maximized in WPF

I know that there are a lot of questions about this subject but it seems that no one tells why this is happening:
Maximized window:
unmaxmimized window:
This only seems happen when I have the medium or the larger setting, with the smaller the text is always sharp:
this is happening for all the text in the application, I already checked that the clear type is enabled and I read something about the allow transparency property I tried with both true and false but nothing changes.
How can I fix this?
Have you tried changing the text options?
TextOptions.TextFormattingMode="Display"
Try to modify the XAML:
<Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
Also, not set the value to "Ideal" which is there by default.
<Viewbox Height="100" Stretch="Uniform" TextOptions.TextFormattingMode="Display">
<TextBlock FontFamily="Georgia">My Cool Text</TextBlock>
</Viewbox>
Could be a bug in WPF but this workaround is in place for many users!

bing maps pushpin and mouseclick

I have several pushpins on the map. When i hover with my mouse over the pushpins i get a dialogbox with some information in it. Now i also want some additional information when i click on the same pushpin. But i can't really figure out how to do this. I tried some things but it didn't work...
This is my code:
<bing:MapItemsControl ItemsSource="{Binding Items}">
<bing:MapItemsControl.ItemTemplate>
<DataTemplate>
<bing:Pushpin bing:MapLayer.Position="{Binding Location}" Background="{Binding Color, Converter={StaticResource brushConverter}}">
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock Text="{Binding Address}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</ToolTipService.ToolTip>
</bing:Pushpin>
</DataTemplate>
</bing:MapItemsControl.ItemTemplate>
</bing:MapItemsControl>
</bing:Map>
Has somebody tried to do this or know how to do this, by far thanks!
I know this is an old question, but maybe it will shine a little light on the right solution, and help someone else, if not you.
As I understand, the Tooltip stuff is already working, you just want to handle the clicks.
So here are some suggestions:
1 - The novice solution:
You can handle the event from the code behind. Since only Buttons have the Click event, you can't use that, but I think MouseLeftButtonDown, or even better MouseLeftButtonUp are equally good for this. Of course, if you have different maps on different controls, you will have to repeat this code on every one of them.
2 - The advanced solution:
Use Behaviors! They are like tiny extensions that can cling on to controls and extend their functionality. In your place, I would put a Behavior on the Pushpins, that would open a panel to display the info you want. You can read more about this topic under the link above!

WPF floating listbox

I have a textbox that I would like to combine with a listbox in such a way that when the user types into the textbox, certain items will appear in the listbox, and the user may select them from there. What I am looking for is behaviour similar to that of the AutoCompleteBox. Sadly, I can't use the existing AutocompleBox in my project for several reasons, so I am trying to come up with similar behaviour on my own. Any ideas?
EDIT:
I would like to avoid using the tooltip as this seems like a hack. Also, when the listbox is displayed, no layouts should be changed either in the control or elsewhere. Is there something like the CSS style overflow available?
OK, it looks like "Popup" is what I am looking for. It's got some of its own quirks, but so far it is working just fine. I am pretty much using it like this..
<DockPanel>
<TextBox Text="{Binding Value}"/>
<Popup Name="popOptions" Width="300" Height="100" AllowsTransparency="True" StaysOpen="False">
<ItemsControl ClipToBounds="False" Background="White" MouseLeftButtonUp="ItemsControl_MouseLeftButtonUp">
<sys:String>ITEM ONE</sys:String>
<sys:String>ITEM TWO</sys:String>
<sys:String>ITEM THREE</sys:String>
</ItemsControl>
</Popup>
</DockPanel>
I am capturing other control events to decide when, and when not to display it.
You could put the ListBox in the TextBox's ToolTip
I'm not sure if that's the best way of doing what you're trying to accomplish, but it will work to make a floating listbox

Silverlight Error "Layout Cycle Detected Layout could not complete" when using custom control

I'm building a custom control in Silverlight by deriving from ContentControl and doing some special formatting to put a dropshadow behind the contents.
I've nearly got it working but have recently ran into a bizarre error. It works fine if it contains anything besides a Border, or a Grid/Stackpanel/etc that does not have an explicitly defined height and width.
I get a JavaScript error in IE, and the text says:
Runtime Error 4008... Layout Cycle Detected... Layout Could Not Complete.
If I specify a height and width on the contained grid/stackpanel/etc it works fine.
There is a ton on the web about this error when too many textboxes are used (over 250), but I'm able to reproduce my error with a single button in a grid.
I have no textboxes at all on the page. The error has to do with a detected infinite loop. I set a few breakpoints in the code and it seems that the "SizeChanged" event is getting called a lot during rendering, and each time the height/width increments by 10.
I'm assuming that setting a default height/width causes it to skip this incrementing of the number, but I have no idea why this error is happening.
Has anyone ran into this or have any ideas?
There is a good blog post on this error here.
Bascially what can happen is you're changing some size in a MeasureOverride somewhere which causes another measure, which changes the size, which causes a measure and so on. I ran into this once before and fixed it by removing any code that caused a layout update or triggered a layout update during the layout cycle.
Update: Since the blog post is gone, quoting it here in full:
Continuing my series of gotchas for Silverlight 2, I wanted to talk about a common error that people are seeing. This error is something new that you might see when moving code from Beta 2 to the Release Candidate or later. In Beta 2, if the layout engine detected a cycle, it didn't throw any errors; as I understand it, the layout was just aborted. But with post Beta2 bits, an error is thrown.
The error you'll get will specify "Layout Cycle Detected" as the message. This error message is very accurate--the layout engine detected a cycle within your layout; or another way to say it, you have an infinite loop in your layout.
The biggest culprit that leads to this error is code within the LayoutUpdated event handler. If your LayoutUpdated event handler does anything to alter the layout of your control, then that will cause the LayoutUpdated event to fire again, and again, and again... :-)
Sometimes you need to have layout altering code within this event handler though, so what is one to do?
First, you should consider whether you really need the layout changes to occur on every call to LayoutUpdated. Would it suffice to handle the Loaded event as well as the Application.Current.Host.Content.Resized event. Between these two events, you'll get notified when the control is loaded into the visual tree, and you'll get notified any time the host is resized, which could cause you to need to change your layout again. Scenarios like modal dialogs should fall into this category.
Second, if you really do need to use LayoutUpdated, you might just need to put some conditions around your layout changes. For instance, if you are calculating a new width and height for your control, before you actually set the width and height, check to make sure the current values differ from what you calculated. This will allow the first LayoutUpdated event to resize your control, which triggers another LayoutUpdated event, but that event will recognize that there's no work to do, and the cycle will end.
These same rules will apply when you're handling the SizeChanged event, or if you're doing any other overrides on the layout of your control.
A common cause is handling SizeChanged and then in the handler doing something that affects the size of the element. Sometimes this is not obvious - it could be modifying child elements which affect the size of their container for instance.
1.If you are using LongListSelector inside ScrollViewer, better remove that. I was facing the same problem and my LongListSelector was inside ScrollViewer. During ItemRealized event, was getting this error.
2.Don't use updatelayout() inside itemrealized..I was using something like
list.UpdateLayout();
list.ScrollTo(e.Container.Content);
Simply use ScrollTo
3.If you are using image inside longlistselector, make sure to set the height and width of the image.
I had the same problem and what i did was put all the layout updates (size changes) in a "invoke" delegate en invoked later, it stops crashing but you there is a good change it's stuck in a loop
I had the same problem but it only occurred extremely rarely, my code hasn't changed for years and only recently someone managed to experience it.
I had a TextBlock inside a LongListSelector DataSource and its FontSize was set to 21. Changing the FontSize to ANY other value fixed the problem for me...
My LongListSelectors is inside a ScrollViewer.
<phone:PanoramaItem x:Name="OwnedGamesPanoramaItem" >
<ScrollViewer Margin="5,-25,0,0">
<StackPanel>
<TextBlock toolkit:TiltEffect.IsTiltEnabled="True" Text="{Binding Path=LocalizedResources.XOwnedGames, Source={StaticResource LocalizedStrings}}" FontFamily="Segoe WP Semibold" CharacterSpacing="10" FontSize="25" Margin="0,10,0,25" TextWrapping="Wrap"/>
<TextBlock x:Name="ownedGameLoadingTextBox" Margin="10" FontSize="26" Text="{Binding Path=LocalizedResources.XLoading, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Center"/>
<phone:LongListSelector x:Name="OwnedGameListBox" Tap="OwnedGameListBoxTap" ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemRealized="OwnedGameListBox_ItemRealized" ItemUnrealized="OwnedGameListBox_ItemUnrealized" BorderThickness="0,20,0,0" >
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Tap="OwnedGameListBoxTap" Margin="0,0,0,12">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Tap="StackPanel_Tap_1">
<Image Width="60" Source="{Binding getSmallImageActualURL}" Height="60" Margin="3" VerticalAlignment="Top" />
<StackPanel Margin="15,0,0,0">
<TextBlock Width="320" TextWrapping="Wrap" Text="{Binding name}" Margin="0,0,0,0" FontSize="32" />
<TextBlock Text="{Binding getTotalPlaytimeFormatted}" Margin="0,0,0,0" TextWrapping="Wrap" FontSize="21" >
<TextBlock.Foreground>
<SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
</TextBlock.Foreground>
</TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</StackPanel>
</ScrollViewer>
</phone:PanoramaItem>
Fix:
<TextBlock Text="{Binding getTotalPlaytimeFormatted}" Margin="0,0,0,0" TextWrapping="Wrap" FontSize="22" >

Resources