Fix: Silverlight AttachmentUpload

Workaround for WebCam opacity bug
This commit is contained in:
Gary Sharp
2013-04-18 14:23:48 +10:00
parent b79723d432
commit 2e1f5a4226
9 changed files with 201 additions and 11 deletions
@@ -87,8 +87,8 @@
<!-- Content Frame Style -->
<Style x:Key="ContentFrameStyle" TargetType="navigation:Frame">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Background" Value="#FFFFFFFF"/>
<Setter Property="BorderBrush" Value="#FFFFFFFF"/>
<Setter Property="Padding" Value="58,15,58,15"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Disco.Silverlight.AttachmentUpload", "Disco.Silverlight.AttachmentUpload.vbproj", "{85747DDC-1389-4A40-9AFC-F57E0992294E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{85747DDC-1389-4A40-9AFC-F57E0992294E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85747DDC-1389-4A40-9AFC-F57E0992294E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85747DDC-1389-4A40-9AFC-F57E0992294E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85747DDC-1389-4A40-9AFC-F57E0992294E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -108,9 +108,6 @@
<Import Include="System.Windows.Shapes" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Disco.BI.VB\BI\Utilities.vb">
<Link>Utilities.vb</Link>
</Compile>
<Compile Include="App.xaml.vb">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
@@ -120,6 +117,7 @@
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="Utilities.vb" />
<Compile Include="Views\FileWindow.xaml.vb">
<DependentUpon>FileWindow.xaml</DependentUpon>
</Compile>
@@ -0,0 +1,151 @@
Imports System.Runtime.CompilerServices
#If Not SILVERLIGHT = 1 Then
Imports System.Web.Mvc
#End If
Namespace BI
<Extension()>
Public Module Utilities
<Extension()>
Public Function StreamToString(stream As IO.Stream) As String
If (stream.Position <> 0) Then
stream.Position = 0
End If
Using sr As IO.StreamReader = New IO.StreamReader(stream)
Return sr.ReadToEnd
End Using
End Function
<Extension()>
Public Function ToFuzzy(d As DateTime) As String
Dim n = DateTime.Now
'' Today
If d.Date = n.Date Then
'' Earlier
If d < n Then
'' Earlier
If d > n.AddMinutes(-1) Then
Return String.Format("A moment ago")
End If
If d > n.AddMinutes(-10) Then
Return String.Format("A few minutes ago")
End If
Else
'' Later
If d < n.AddMinutes(1) Then
Return String.Format("In a moment")
End If
If d < n.AddMinutes(10) Then
Return String.Format("In a few minutes")
End If
End If
Return String.Format("Today at {0:h:mm tt}", d)
End If
'' Past
If d.Date < n.Date Then
'' Yesterday
If d.Date = n.Date.AddDays(-1) Then
Return String.Format("Yesterday at {0:h:mm tt}", d)
End If
'' Last Week
Dim weekStart = n.Date.AddDays(-7)
If d > weekStart Then
Return String.Format("Last {0:dddd} at {0:h:mm tt}", d)
End If
'' This Year
Dim yearStart = New Date(n.Year, 1, 1)
If d > yearStart Then
'' Weeks
Dim weekNumber As Integer = ((n.DayOfYear - d.DayOfYear) / 7)
Return String.Format("{0} Weeks ago, {1:ddd, d MMM}", weekNumber, d)
End If
End If
'' Future
If d.Date > n.Date Then
'' Tomorrow
If d.Date = n.Date.AddDays(1) Then
Return String.Format("Tomorrow at {0:h:mm tt}", d)
End If
'' Next Week
Dim weekEnd = n.Date.AddDays(7)
If d < weekEnd Then
Return String.Format("Next {0:dddd} at {0:h:mm tt}", d)
End If
'' This Year
Dim nextYearStart = New Date(n.Year + 1, 1, 1)
If d < nextYearStart Then
'' Weeks
Dim weekNumber As Integer = ((d.DayOfYear - n.DayOfYear) / 7)
Return String.Format("In {0} Weeks, {1:ddd, d MMM}", weekNumber, d)
End If
End If
Return d.ToString("ddd, d MMM yyyy")
End Function
<Extension()>
Public Function ToFuzzy(d As DateTime?, Optional NullValue As String = "N/A") As String
If d.HasValue Then
Return ToFuzzy(d.Value)
Else
Return NullValue
End If
End Function
<Extension()>
Public Function ToFullDateTime(d As DateTime) As String
Return d.ToString("ddd, d MMM yyyy @ h:mm:sstt")
End Function
<Extension()>
Public Function ToFullDateTime(d As DateTime?, Optional NullValue As String = "N/A") As String
If d.HasValue Then
Return ToFullDateTime(d.Value)
Else
Return NullValue
End If
End Function
<Extension()>
Public Function ToJavascriptDate(d As DateTime?, Optional DefaultDate As DateTime? = Nothing) As String
If d.HasValue Then
Return ToJavascriptDate(d.Value)
Else
If DefaultDate.HasValue Then
Return ToJavascriptDate(DefaultDate.Value)
Else
Return "null"
End If
End If
End Function
<Extension()>
Public Function ToJavascriptDate(d As DateTime) As String
Return String.Format("new Date({0}, {1}, {2}, {3}, {4}, {5})", d.Year, d.Month - 1, d.Day, d.Hour, d.Minute, d.Second)
End Function
#If Not SILVERLIGHT = 1 Then
<Extension()>
Public Function ToSelectListItems(Items As List(Of String), Optional SelectedItem As String = Nothing) As List(Of SelectListItem)
If SelectedItem Is Nothing Then
Return Items.Select(Function(item) New SelectListItem() With {.Value = item,
.Text = item}).ToList()
Else
Return Items.Select(Function(item) New SelectListItem() With {.Value = item,
.Text = item,
.Selected = (item = SelectedItem)}).ToList()
End If
End Function
#End If
End Module
End Namespace
@@ -11,8 +11,17 @@
<Button x:Name="ButtonStartWebCam" Content="START WEBCAM" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="14, 8" />
</Grid>
<Grid x:Name="WebCamShow" Visibility="Collapsed">
<Rectangle x:Name="WebCamHost" />
<Button x:Name="ButtonCapture" Content="CAPTURE IMAGE" HorizontalAlignment="Center" VerticalAlignment="Bottom" Padding="14, 8" />
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Background="Black">
<Rectangle x:Name="WebCamHost" OpacityMask="White" />
</Border>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom" Grid.Row="1" Margin="0, 10, 0, 0">
<Button x:Name="ButtonCapture" Content="CAPTURE IMAGE (Michael)" HorizontalAlignment="Center" Padding="14, 8" />
<TextBlock x:Name="TextBlockWebCamFormat" HorizontalAlignment="Center" Margin="0, 6, 0, 0"></TextBlock>
</StackPanel>
</Grid>
<Border x:Name="WebCamCaptured" Visibility="Collapsed" Width="600" Height="450" Background="#BBffe3cb" BorderBrush="#FFDB761D" BorderThickness="4" CornerRadius="4">
<Grid>
@@ -26,7 +35,9 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle x:Name="WebCamCapturedImage" Grid.ColumnSpan="4" Margin="14" />
<Border Background="Black" Grid.ColumnSpan="4" Margin="14">
<Rectangle x:Name="WebCamCapturedImage" />
</Border>
<Button x:Name="ButtonCancel" Grid.Row="1" Grid.Column="0" Content="CANCEL" HorizontalAlignment="Center" VerticalAlignment="Bottom" Padding="14, 8" Margin="6" />
<TextBlock Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="10 0">Comments:</TextBlock>
<TextBox Grid.Row="1" Grid.Column="2" x:Name="TextBoxComments" Height="24" />
@@ -21,14 +21,20 @@ Partial Public Class WebCam
_CaptureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()
'' Get Best Quality Image
_CaptureSource.VideoCaptureDevice.DesiredFormat = (From f In _CaptureSource.VideoCaptureDevice.SupportedFormats Where f.PixelHeight <= 720
Order By (f.FramesPerSecond * f.PixelHeight * f.PixelWidth) Descending).FirstOrDefault()
Dim format = (From f In _CaptureSource.VideoCaptureDevice.SupportedFormats Where f.PixelHeight <= 720 And f.Stride = 0
Order By (f.PixelHeight * f.PixelWidth) Descending Order By f.FramesPerSecond).FirstOrDefault()
TextBlockWebCamFormat.Text = String.Format("{0}x{1} at {2}fps", format.PixelWidth, format.PixelHeight, format.FramesPerSecond)
_CaptureSource.VideoCaptureDevice.DesiredFormat = format
AddHandler _CaptureSource.CaptureImageCompleted, AddressOf CaptureSource_CaptureImageCompleted
_VideoBrush = New VideoBrush()
_VideoBrush.Stretch = Stretch.Uniform
_VideoBrush.SetSource(_CaptureSource)
WebCamHost.Fill = _VideoBrush
ButtonCapture.Focus()
End If
If (CaptureDeviceConfiguration.AllowedDeviceAccess) Then